Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4.  
  5. import javax.swing.*;
  6.  
  7. class Main extends JDialog {
  8. int score = 1;
  9.  
  10. public Main() {
  11. setSize(200, 200);
  12. setBackground(Color.gray);
  13. JPanel topPanel = new JPanel();
  14. topPanel.setLayout(new GridLayout(3, 2));
  15. getContentPane().add(topPanel);
  16. topPanel.setBackground(Color.lightGray);
  17. JButton done = new JButton("Done");
  18. JRadioButton a = new JRadioButton("One");
  19. JRadioButton b = new JRadioButton("Two");
  20. JRadioButton c = new JRadioButton("Three");
  21. JRadioButton d = new JRadioButton("Four");
  22. topPanel.add(a);
  23. topPanel.add(b);
  24. topPanel.add(c);
  25. topPanel.add(d);
  26. topPanel.add(done);
  27.  
  28. ButtonGroup grup = new ButtonGroup();
  29.  
  30. grup.add(a);
  31. grup.add(b);
  32. grup.add(c);
  33. grup.add(d);
  34.  
  35. if (a.isSelected())
  36. score = score + 1;
  37.  
  38. done.addActionListener(new ActionListener() {
  39.  
  40. public void actionPerformed(ActionEvent e) {
  41. JOptionPane.showMessageDialog(Main.this, "Your score is " + score + " points.", "Login",
  42. JOptionPane.INFORMATION_MESSAGE);
  43. dispose();
  44. }
  45. });
  46. }
  47.  
  48. public static void main(String args[]) {
  49. Main mainFrame = new Main();
  50. mainFrame.setVisible(true);
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement