本文整理汇总了Java中java.awt.Choice.addItemListener方法的典型用法代码示例。如果您正苦于以下问题:Java Choice.addItemListener方法的具体用法?Java Choice.addItemListener怎么用?Java Choice.addItemListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Choice
的用法示例。
在下文中一共展示了Choice.addItemListener方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DrawControls
import java.awt.Choice; //导入方法依赖的package包/类
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
this.target = target;
setLayout(new FlowLayout());
setBackground(Color.lightGray);
target.setForeground(Color.red);
CheckboxGroup group = new CheckboxGroup();
Checkbox b;
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.red);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.green);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.blue);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.pink);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.orange);
add(b = new Checkbox(null, group, true));
b.addItemListener(this);
b.setForeground(Color.black);
target.setForeground(b.getForeground());
Choice shapes = new Choice();
shapes.addItemListener(this);
shapes.addItem("Lines");
shapes.addItem("Points");
shapes.setBackground(Color.lightGray);
add(shapes);
}
示例2: CardTest
import java.awt.Choice; //导入方法依赖的package包/类
@SuppressWarnings("LeakingThisInConstructor")
public CardTest() {
setLayout(new BorderLayout());
add("Center", cards = new CardPanel(this));
Panel p = new Panel();
p.setLayout(new FlowLayout());
add("South", p);
Button b = new Button("first");
b.addActionListener(this);
p.add(b);
b = new Button("next");
b.addActionListener(this);
p.add(b);
b = new Button("previous");
b.addActionListener(this);
p.add(b);
b = new Button("last");
b.addActionListener(this);
p.add(b);
Choice c = new Choice();
c.addItem("one");
c.addItem("two");
c.addItem("three");
c.addItem("four");
c.addItem("five");
c.addItem("six");
c.addItemListener(this);
p.add(c);
}
示例3: showDialog
import java.awt.Choice; //导入方法依赖的package包/类
/**
* Show dialog.
*
* @return the image plus
*/
public ImagePlus showDialog(){
gd = new GenericDialog("Add Image");
gd.setResizable(true);
gd.pack();
String[] source = {"From Image","From File"};
gd.addChoice("Image Source:", source, null);
addImageChoice();
// automatically update name if a different image is selected
final Choice im = (Choice) gd.getChoices().get(0);
im.addItemListener(this);
gd.showDialog();
if(gd.wasCanceled())
return null;
if(!fromFile) {
img = fromImage();
}
return img;
}
示例4: enableChannelChoice
import java.awt.Choice; //导入方法依赖的package包/类
private final void enableChannelChoice(final Choice controller, final Choice target, final int[] nostackIDs)
{
setRGB(nostackIDs[controller.getSelectedIndex()], target);
controller.addItemListener(new ItemListener()
{
@Override
public void itemStateChanged(ItemEvent ie)
{
setRGB(nostackIDs[controller.getSelectedIndex()], target);
}
});
}
示例5: enableChannelChoice
import java.awt.Choice; //导入方法依赖的package包/类
private final void enableChannelChoice(final Choice controller, final Choice target, final int[] stackIDs)
{
setRGB(stackIDs[controller.getSelectedIndex()], target);
controller.addItemListener(new ItemListener()
{
@Override
public void itemStateChanged(ItemEvent ie)
{
setRGB(stackIDs[controller.getSelectedIndex()], target);
}
});
}
示例6: addListeners
import java.awt.Choice; //导入方法依赖的package包/类
protected void addListeners(
final GenericDialog gd,
final Choice choice,
final Label label1,
final Label label2 )
{
choice.addItemListener( new ItemListener()
{
@Override
public void itemStateChanged(ItemEvent e)
{
update( spimData, choice, label1, label2 );
}
});
update( spimData, choice, label1, label2 );
}
示例7: initComponents
import java.awt.Choice; //导入方法依赖的package包/类
private void initComponents() {
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(100, 100, 439, 337);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
txtUsuario = new JTextField();
txtUsuario.setFont(new Font("Tahoma", Font.BOLD, 11));
txtUsuario.setEditable(false);
txtUsuario.setBounds(16, 36, 314, 23);
contentPane.add(txtUsuario);
txtUsuario.setColumns(10);
JLabel lblUsuario = new JLabel("Usuario");
lblUsuario.setBounds(16, 21, 61, 14);
contentPane.add(lblUsuario);
txtCodigo = new JTextField();
txtCodigo.setFont(new Font("Tahoma", Font.BOLD, 11));
txtCodigo.setEditable(false);
txtCodigo.setBounds(16, 146, 314, 23);
contentPane.add(txtCodigo);
txtCodigo.setColumns(10);
lblCodigo = new JLabel("Codigo ");
lblCodigo.setBounds(16, 128, 126, 14);
contentPane.add(lblCodigo);
lblfecha_prestDePrestamo = new JLabel("Fecha de pr\u00E9stamo");
lblfecha_prestDePrestamo.setBounds(16, 193, 148, 14);
contentPane.add(lblfecha_prestDePrestamo);
btnBuscarCodigo = new JButton("...");
btnBuscarCodigo.setBounds(346, 146, 61, 23);
contentPane.add(btnBuscarCodigo);
btnBuscarCodigo.setEnabled(false);
btnBuscarCodigo.addActionListener(this);
btnBuscarUsuario = new JButton("...");
btnBuscarUsuario.setBounds(346, 35, 61, 23);
contentPane.add(btnBuscarUsuario);
btnBuscarUsuario.addActionListener(this);
tipo = new Choice();
tipo.setBounds(16, 91, 115, 20);
tipo.add("Seleccione");
tipo.add("Libro");
tipo.add("Revista");
tipo.add("CDROM");
tipo.add("Articulo");
tipo.setEnabled(false);
tipo.addItemListener(this);
contentPane.add(tipo);
lblTipo = new JLabel("Tipo");
lblTipo.setBounds(16, 71, 46, 14);
contentPane.add(lblTipo);
addWindowListener(this);
setVisible(true);
setLocationRelativeTo(null);
}
示例8: init
import java.awt.Choice; //导入方法依赖的package包/类
public void init ()
{
cursorChoice = new Choice();
cursorChoice.add ("Default");
cursorChoice.add ("Crosshair");
cursorChoice.add ("Text");
cursorChoice.add ("Wait");
cursorChoice.add ("Southwest Resize");
cursorChoice.add ("Southeast Resize");
cursorChoice.add ("Northwest Resize");
cursorChoice.add ("Northeast Resize");
cursorChoice.add ("North Resize");
cursorChoice.add ("South Resize");
cursorChoice.add ("West Resize");
cursorChoice.add ("East Resize");
cursorChoice.add ("Hand");
cursorChoice.add ("Move");
cursorChoice.addItemListener(this);
add (cursorChoice, "North");
cursorCanvas = new Canvas ()
{
public void paint (Graphics g)
{
Dimension d = this.getSize();
g.setColor(Color.white);
g.fillRect(0, 0, d.width, d.height/2);
g.setColor(Color.black);
g.fillRect(0, d.height/2, d.width, d.height/2);
g.setColor(this.getBackground());
g.fillRect(d.width/3, d.height/3, d.width/3,
d.height/3);
}
};
cursorCanvas.setSize (80,80);
add (cursorCanvas, "Center");
Button cb = new Button ("Close");
cb.addActionListener(new ActionListener () {
public void actionPerformed (ActionEvent e) {
dispose();
}
});
add (cb, "South");
setTitle ("Cursors");
pack();
}
示例9: initInputPanel
import java.awt.Choice; //导入方法依赖的package包/类
private void initInputPanel(Panel p) {
GridBagConstraints gbc=
new GridBagConstraints();
p.setLayout(new GridBagLayout());
gbc.weightx=100;
gbc.weighty=100;
gbc.gridwidth=1;
gbc.gridheight=1;
gbc.fill=GridBagConstraints.HORIZONTAL;
gbc.anchor=GridBagConstraints.WEST;
gbc.gridx=0;
gbc.gridy=0;
Label typeLabel=new Label("Type");
p.add(typeLabel,gbc);
gbc.gridx=1;
gbc.gridwidth=GridBagConstraints.REMAINDER;
Label valueLabel=new Label("Value");
p.add(valueLabel,gbc);
gbc.gridx=0;
gbc.gridy=1;
Choice type=new Choice();
type.add("Byte");
type.add("Short");
type.add("Character");
type.add("Integer");
type.add("Long");
type.add("Float");
type.add("Double");
type.add("String");
type.add("Object");
type.select("Float");
type.addItemListener(new TypeChoiceCommand());
p.add(type,gbc);
gbc.gridx=1;
gbc.gridwidth=GridBagConstraints.REMAINDER;
value=new ValueChoice();
p.add(value,gbc);
gbc.gridx=0;
gbc.gridy=2;
gbc.gridwidth=1;
gbc.fill=GridBagConstraints.NONE;
Button reset=new Button("Reset");
reset.addActionListener(new ResetCommand());
p.add(reset,gbc);
gbc.gridx=1;
gbc.gridwidth=GridBagConstraints.REMAINDER;
Button position=new Button("Add");
position.addActionListener(new AddCommand());
p.add(position,gbc);
gbc.gridx=0;
gbc.gridy=3;
gbc.gridwidth=1;
gbc.gridheight=GridBagConstraints.REMAINDER;
gbc.fill=GridBagConstraints.HORIZONTAL;
Label format = new Label("Control String");
p.add(format,gbc);
gbc.gridx=1;
TextField formatString = new TextField(40);
gbc.gridwidth=GridBagConstraints.REMAINDER;
formatString.addTextListener(new FormatCommand());
p.add(formatString,gbc);
}
示例10: init
import java.awt.Choice; //导入方法依赖的package包/类
public void init ()
{
cursorChoice = new Choice();
cursorChoice.add ("Default");
cursorChoice.add ("Crosshair");
cursorChoice.add ("Text");
cursorChoice.add ("Wait");
cursorChoice.add ("Southwest Resize");
cursorChoice.add ("Southeast Resize");
cursorChoice.add ("Northwest Resize");
cursorChoice.add ("Northeast Resize");
cursorChoice.add ("North Resize");
cursorChoice.add ("South Resize");
cursorChoice.add ("West Resize");
cursorChoice.add ("East Resize");
cursorChoice.add ("Hand");
cursorChoice.add ("Move");
cursorChoice.addItemListener(this);
add (cursorChoice, "North");
cursorCanvas = new Canvas ()
{
public void paint (Graphics g)
{
Dimension d = this.getSize();
g.setColor(Color.white);
g.fillRect(0, 0, d.width, d.height/2);
g.setColor(Color.black);
g.fillRect(0, d.height/2, d.width, d.height/2);
g.setColor(this.getBackground());
g.fillRect(d.width/3, d.height/3, d.width/3,
d.height/3);
}
};
cursorCanvas.setSize (80,80);
add (cursorCanvas, "Center");
Button cb = new Button ("Close");
cb.addActionListener(new ActionListener () {
public void actionPerformed (ActionEvent e) {
dispose();
}
});
add (cb, "South");
setTitle ("Cursors");
pack();
}
示例11: main
import java.awt.Choice; //导入方法依赖的package包/类
public static void main(String[] args) {
String s = "Java Tips";
final int size = 64;
if (args.length > 0)
s = args[0];
Panel controls = new Panel();
final Choice choice = new Choice();
GraphicsEnvironment ge = GraphicsEnvironment
.getLocalGraphicsEnvironment();
Font[] allFonts = ge.getAllFonts();
for (int i = 0; i < allFonts.length; i++)
choice.addItem(allFonts[i].getName());
Font defaultFont = new Font(allFonts[0].getName(), Font.PLAIN, size);
final TextBouncer bouncer = new TextBouncer(s, defaultFont);
Frame f = new AnimationFrame(bouncer);
f.setFont(new Font("Serif", Font.PLAIN, 12));
controls.add(bouncer.createCheckbox("Antialiasing",
TextBouncer.ANTIALIASING));
controls.add(bouncer.createCheckbox("Gradient", TextBouncer.GRADIENT));
controls.add(bouncer.createCheckbox("Shear", TextBouncer.SHEAR));
controls.add(bouncer.createCheckbox("Rotate", TextBouncer.ROTATE));
controls.add(bouncer.createCheckbox("Axes", TextBouncer.AXES));
Panel fontControls = new Panel();
choice.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent ie) {
Font font = new Font(choice.getSelectedItem(), Font.PLAIN, size);
bouncer.setFont(font);
}
});
fontControls.add(choice);
Panel allControls = new Panel(new GridLayout(2, 1));
allControls.add(controls);
allControls.add(fontControls);
f.add(allControls, BorderLayout.NORTH);
f.setSize(300,300);
f.setVisible(true);
}
示例12: addInputSourceToDialog
import java.awt.Choice; //导入方法依赖的package包/类
/**
* Add a list of input sources to the generic dialog. The choice field will be named inputName. If the file input
* option
* is true then a field will be added name 'Input_file'.
*
* @param gd
* @param inputName
* @param inputOption
* The option to select by default
* @param source
* @param fileInput
*/
@SuppressWarnings("unused")
public static void addInputSourceToDialog(final ExtendedGenericDialog gd, String inputName, String inputOption,
ArrayList<String> source, boolean fileInput)
{
String[] options = source.toArray(new String[source.size()]);
// Find the option
inputOption = removeFormatting(inputOption);
int optionIndex = 0;
for (int i = 0; i < options.length; i++)
{
String name = removeFormatting(options[i]);
if (name.equals(inputOption))
{
optionIndex = i;
break;
}
}
final Choice c = gd.addAndGetChoice(inputName, options, options[optionIndex]);
if (fileInput)
{
final TextField tf = gd.addFilenameField("Input_file", inputFilename);
final JButton b = gd.getLastOptionButton();
// Add a listener to the choice to enable the file input field.
// Currently we hide the filename field and pack the dialog.
// We may wish to just disable the fields and leave them there.
// This could be a user configured option in a global GDSC settings class.
if (Utils.isShowGenericDialog())
{
final Label l = gd.getLastLabel();
final Panel p = gd.getLastPanel();
ItemListener listener = new ItemListener()
{
public void itemStateChanged(ItemEvent e)
{
boolean enable = INPUT_FILE.equals(c.getSelectedItem());
if (enable != l.isVisible())
{
l.setVisible(enable);
p.setVisible(enable);
//tf.setVisible(enable);
//b.setVisible(enable);
gd.pack();
}
}
};
// Run once to set up
listener.itemStateChanged(null);
c.addItemListener(listener);
}
}
}
示例13: createFrame
import java.awt.Choice; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private void createFrame()
{
Panel mainPanel = new Panel();
add(mainPanel);
imageChoice = new Choice();
mainPanel.add(createChoicePanel(imageChoice, null, null, "Image"));
imageChoice.addItemListener(this);
synchroniseButton = new JToggleButton("Synchronise");
synchroniseButton.addItemListener(this);
helpButton = new JButton("Help");
helpButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
String macro = "run('URL...', 'url="+gdsc.help.URL.UTILITY+"');";
new MacroRunner(macro);
}
});
JPanel buttonPanel = new JPanel();
FlowLayout l = new FlowLayout();
l.setVgap(0);
buttonPanel.setLayout(l);
buttonPanel.add(synchroniseButton, BorderLayout.CENTER);
buttonPanel.add(helpButton, BorderLayout.CENTER);
mainPanel.add(buttonPanel);
mainPanel.add(createLabelPanel("Images to sync:"));
listModel = new DefaultListModel();
childList = new JList(listModel);
childList.setVisibleRowCount(15);
JScrollPane scrollPane = new JScrollPane(childList);
mainPanel.add(scrollPane);
childList.addListSelectionListener(this);
GridBagLayout mainGrid = new GridBagLayout();
int y = 0;
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.fill = GridBagConstraints.BOTH;
c.anchor = GridBagConstraints.WEST;
c.gridwidth = 1;
c.insets = new Insets(2, 2, 2, 2);
for (Component comp : mainPanel.getComponents())
{
c.gridy = y++;
mainGrid.setConstraints(comp, c);
}
mainPanel.setLayout(mainGrid);
}