Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- class Main extends JDialog {
- int score = 1;
- public Main() {
- setSize(200, 200);
- setBackground(Color.gray);
- JPanel topPanel = new JPanel();
- topPanel.setLayout(new GridLayout(3, 2));
- getContentPane().add(topPanel);
- topPanel.setBackground(Color.lightGray);
- JButton done = new JButton("Done");
- JRadioButton a = new JRadioButton("One");
- JRadioButton b = new JRadioButton("Two");
- JRadioButton c = new JRadioButton("Three");
- JRadioButton d = new JRadioButton("Four");
- topPanel.add(a);
- topPanel.add(b);
- topPanel.add(c);
- topPanel.add(d);
- topPanel.add(done);
- ButtonGroup grup = new ButtonGroup();
- grup.add(a);
- grup.add(b);
- grup.add(c);
- grup.add(d);
- if (a.isSelected())
- score = score + 1;
- done.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- JOptionPane.showMessageDialog(Main.this, "Your score is " + score + " points.", "Login",
- JOptionPane.INFORMATION_MESSAGE);
- dispose();
- }
- });
- }
- public static void main(String args[]) {
- Main mainFrame = new Main();
- mainFrame.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement