List of usage examples for javax.swing JButton JButton
public JButton(Action a)
Action
supplied. From source file:Main.java
public static void main(String[] args) { final Timer timer; final JProgressBar progressBar = new JProgressBar(); final JButton button = new JButton("Start"); JFrame f = new JFrame(); f.setLayout(new FlowLayout()); f.add(progressBar);//from w w w . jav a2s .c om f.add(button); ActionListener updateProBar = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { int val = progressBar.getValue(); if (val >= 100) { // timer.stop(); button.setText("End"); return; } progressBar.setValue(++val); } }; timer = new Timer(50, updateProBar); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (timer.isRunning()) { timer.stop(); button.setText("Start"); } else if (button.getText() != "End") { timer.start(); button.setText("Stop"); } } }); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setResizable(false); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Action action = new ShowAction(); JButton button = new JButton(action); frame.add(button, BorderLayout.CENTER); frame.setSize(350, 150);/*from ww w. j av a 2 s.c o m*/ frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("Justified Titled Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border loweredBorder = BorderFactory.createLoweredBevelBorder(); JButton loweredButton = new JButton("Lowered"); loweredButton.setBorder(loweredBorder); Container contentPane = frame.getContentPane(); contentPane.add(loweredButton);/*from w w w. j a va2 s . c o m*/ frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("Justified Titled Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border raisedBorder = BorderFactory.createRaisedSoftBevelBorder(); JButton raisedButton = new JButton("Raised"); raisedButton.setBorder(raisedBorder); Container contentPane = frame.getContentPane(); contentPane.add(raisedButton);//from w w w .ja v a 2s . c o m frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("Layout"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); contentPane.setLayout(new FlowLayout()); for (int i = 1; i <= 5; i++) { contentPane.add(new JButton("Button " + i)); }//from w w w . j av a2 s . c o m frame.pack(); frame.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Justified Titled Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border raisedBorder = BorderFactory.createRaisedBevelBorder(); JButton raisedButton = new JButton("Raised"); raisedButton.setBorder(raisedBorder); Container contentPane = frame.getContentPane(); contentPane.add(raisedButton);//from w w w .jav a 2 s . c o m frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("JFrame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JButton closeButton = new JButton("Close"); contentPane.add(closeButton);//from w ww.j a va2 s.c om closeButton.addActionListener(e -> System.exit(0)); // Add a MouseListener to the JButton closeButton.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { closeButton.setText("Mouse has entered!"); } @Override public void mouseExited(MouseEvent e) { closeButton.setText("Mouse has exited!"); } }); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("Justified Titled Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border loweredBorder = BorderFactory.createLoweredSoftBevelBorder(); JButton loweredButton = new JButton("Lowered"); loweredButton.setBorder(loweredBorder); Container contentPane = frame.getContentPane(); contentPane.add(loweredButton);/*from w ww. j a v a2 s.c o m*/ frame.setSize(300, 200); frame.setVisible(true); }
From source file:ActiveSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Active Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); UIManager.put(LABEL_FACTORY, new ActiveLabel()); final JPanel panel = new JPanel(); JButton button = new JButton("Get"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { JLabel label = (JLabel) UIManager.get(LABEL_FACTORY); panel.add(label);/* ww w . j a v a2s.com*/ panel.revalidate(); } }; button.addActionListener(actionListener); frame.add(panel, BorderLayout.CENTER); frame.add(button, BorderLayout.SOUTH); frame.setSize(200, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame("Empty Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border emptyBorder = BorderFactory.createEmptyBorder(20, 20, 0, 0); JButton emptyButton = new JButton("With Empty"); emptyButton.setBorder(emptyBorder);/*from ww w . ja va 2 s.com*/ JButton nonemptyButton = new JButton("Without Empty"); Container contentPane = frame.getContentPane(); contentPane.add(emptyButton, BorderLayout.NORTH); contentPane.add(nonemptyButton, BorderLayout.SOUTH); frame.pack(); frame.setSize(300, frame.getHeight()); frame.setVisible(true); }