Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- public class guii {
- static class GUI extends JFrame {
- private static final long serialVersionUID = 1L;
- private JFrame frame;
- private JPanel panel;
- private JButton startbutton, cancelbutton;
- private GridBagConstraints c = new GridBagConstraints();
- public GUI() {
- createAndShowGui();
- frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- }
- public void createAndShowGui() {
- frame = new JFrame("GUI");
- frame.setResizable(false);
- frame.setSize(300, 300);
- panel = new JPanel(new GridBagLayout());
- frame.add(panel);
- c.gridx = 5;
- c.gridy = 5;
- startbutton = new JButton("start");
- cancelbutton = new JButton("quit");
- panel.add(startbutton, c);
- panel.add(cancelbutton);
- startbutton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- System.out.println("start");
- dispose();
- }
- });
- cancelbutton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- System.out.println("cancel");
- dispose();
- }
- });
- }
- }
- public static void main(String[] args) {
- final GUI gui = new GUI();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement