List of usage examples for javax.swing JLabel JLabel
public JLabel(Icon image)
JLabel
instance with the specified image. From source file:Main.java
public static void main(String[] args) { JRadioButton button1 = new JRadioButton("Red"); JRadioButton button2 = new JRadioButton("Green"); JRadioButton button3 = new JRadioButton("Blue"); ButtonGroup colorButtonGroup = new ButtonGroup(); colorButtonGroup.add(button1);//ww w . j av a 2 s. c o m colorButtonGroup.add(button2); colorButtonGroup.add(button3); button1.setSelected(true); JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JLabel("Color:")); frame.add(button1); frame.add(button2); frame.add(button3); frame.pack(); frame.setVisible(true); System.out.println(getSelection(colorButtonGroup)); }
From source file:Main.java
public static void main(String[] args) { ScriptEngine engine = new ScriptEngineManager().getEngineByExtension("js"); String[] ops = { "+", "-", "*", "/" }; JPanel gui = new JPanel(new BorderLayout(2, 2)); JPanel labels = new JPanel(new GridLayout(0, 1)); gui.add(labels, BorderLayout.WEST); labels.add(new JLabel("a")); labels.add(new JLabel("operand")); labels.add(new JLabel("b")); labels.add(new JLabel("=")); JPanel controls = new JPanel(new GridLayout(0, 1)); gui.add(controls, BorderLayout.CENTER); JTextField a = new JTextField(10); controls.add(a);// ww w . j a v a 2 s. com JComboBox operand = new JComboBox(ops); controls.add(operand); JTextField b = new JTextField(10); controls.add(b); JTextField output = new JTextField(10); controls.add(output); ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent ae) { String expression = a.getText() + operand.getSelectedItem() + b.getText(); try { Object result = engine.eval(expression); if (result == null) { output.setText("Output was 'null'"); } else { output.setText(result.toString()); } } catch (ScriptException se) { output.setText(se.getMessage()); } } }; operand.addActionListener(al); a.addActionListener(al); b.addActionListener(al); JOptionPane.showMessageDialog(null, gui); }
From source file:Main.java
public static void main(String[] args) { Runnable r = new Runnable() { @Override/* w ww . j ava 2s . c o m*/ public void run() { JPanel gui = new JPanel(); final AnimatedImage[] tiles = new AnimatedImage[2]; for (int ii = 0; ii < tiles.length; ii++) { tiles[ii] = new AnimatedImage(); gui.add(new JLabel(new ImageIcon(tiles[ii]))); } ActionListener listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { for (int i = 0; i < tiles.length; i++) { tiles[i].paintImage(); gui.repaint(); } } }; Timer timer = new Timer(50, listener); timer.start(); JOptionPane.showMessageDialog(null, gui); timer.stop(); } }; SwingUtilities.invokeLater(r); }
From source file:JRadioButtonTest.java
public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("JRadioButton Test"); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JRadioButton button1 = new JRadioButton("Red"); JRadioButton button2 = new JRadioButton("Green"); JRadioButton button3 = new JRadioButton("Blue"); ButtonGroup colorButtonGroup = new ButtonGroup(); colorButtonGroup.add(button1);/*from ww w . j av a 2 s.c o m*/ colorButtonGroup.add(button2); colorButtonGroup.add(button3); button1.setSelected(true); frame.add(new JLabel("Color:")); frame.add(button1); frame.add(button2); frame.add(button3); frame.pack(); frame.setVisible(true); }
From source file:JFormattedTextFieldDateInputSampleELocaleFRENCH.java
public static void main(String args[]) { JFrame frame = new JFrame("Date/Time Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label;/*ww w.java 2 s . c o m*/ JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format dayOfWeek = new SimpleDateFormat("E", Locale.FRENCH); label = new JLabel("French day of week:"); input = new JFormattedTextField(dayOfWeek); input.setValue(new Date()); input.setColumns(20); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.add(new JTextField()); frame.pack(); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("Number Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = new Font("SansSerif", Font.BOLD, 16); JLabel label;/*from ww w. jav a 2 s . com*/ JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format number = NumberFormat.getNumberInstance(Locale.FRENCH); label = new JLabel("French Number:"); input = new JFormattedTextField(number); input.setValue(2424.50); input.setColumns(20); input.setFont(font); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("Number Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = new Font("SansSerif", Font.BOLD, 16); JLabel label;/*from w w w . j a v a 2 s. co m*/ JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format currency = NumberFormat.getCurrencyInstance(Locale.UK); label = new JLabel("UK Currency:"); input = new JFormattedTextField(currency); input.setValue(2424.50); input.setColumns(20); input.setFont(font); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JRadioButton button1 = new JRadioButton("Red"); JRadioButton button2 = new JRadioButton("Green"); button2.setMnemonic(KeyEvent.VK_G); JRadioButton button3 = new JRadioButton("Blue"); ButtonGroup colorButtonGroup = new ButtonGroup(); colorButtonGroup.add(button1);//w ww .j a va 2s .c om colorButtonGroup.add(button2); colorButtonGroup.add(button3); button1.setSelected(true); JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JLabel("Color:")); frame.add(button1); frame.add(button2); frame.add(button3); frame.pack(); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("Number Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = new Font("SansSerif", Font.BOLD, 16); JLabel label;// w w w . ja v a2 s . c o m JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format integer = NumberFormat.getIntegerInstance(Locale.ITALIAN); label = new JLabel("Italian integer:"); input = new JFormattedTextField(integer); input.setValue(2424.50); input.setColumns(20); input.setFont(font); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { FlowLayout layout = new FlowLayout(FlowLayout.LEADING, horizontalGap, verticalGap); JButton button = new JButton("Discard"); JLabel[] panels = new JLabel[5]; JFrame frame = new JFrame("Poker"); frame.setSize(width, height);// ww w .j a va 2 s .c om frame.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); JPanel deckPanel = new JPanel(layout); for (int i = 0; i < 5; i++) { panels[i] = new JLabel("" + i); deckPanel.add(panels[i]); } frame.getContentPane().add(deckPanel); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); buttonPanel.add(button); frame.getContentPane().add(buttonPanel, BorderLayout.SOUTH); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }