Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JButton;
- import javax.swing.JOptionPane;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import java.awt.Color;
- public class NiceGui {
- private JFrame frmSomegame;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- NiceGui window = new NiceGui();
- window.frmSomegame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public NiceGui() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frmSomegame = new JFrame();
- frmSomegame.setTitle("SomeGame");
- frmSomegame.getContentPane().setBackground(Color.BLUE);
- frmSomegame.setBounds(100, 100, 450, 300);
- frmSomegame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frmSomegame.getContentPane().setLayout(null);
- JButton btnNewButton = new JButton("Play");
- btnNewButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- JOptionPane.showMessageDialog(null,"Hello!");
- }
- });
- btnNewButton.setBounds(28, 41, 133, 50);
- frmSomegame.getContentPane().add(btnNewButton);
- JButton btnNewButton_1 = new JButton("Credit");
- btnNewButton_1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- JOptionPane.showMessageDialog(null,"Created by Calvin");
- }
- });
- btnNewButton_1.setBounds(25, 142, 136, 50);
- frmSomegame.getContentPane().add(btnNewButton_1);
- JButton btnNewButton_2 = new JButton("Quit");
- btnNewButton_2.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- int result = JOptionPane.showConfirmDialog(null,"Do you want to quit?","Are you sure?",JOptionPane.YES_NO_OPTION) ;
- if(result == JOptionPane.YES_OPTION) {
- System.exit(0) ;
- }
- }
- });
- btnNewButton_2.setBounds(249, 142, 156, 50);
- frmSomegame.getContentPane().add(btnNewButton_2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment