Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.samkough.main;
- /*
- LINKS:
- http://www.wikihow.com/Create-a-Swing-GUI-in-Java
- https://stackoverflow.com/questions/144892/how-to-centre-a-window-in-java
- */
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.*;
- @SuppressWarnings("serial")
- public class Swing extends JFrame implements ActionListener
- {
- JPanel mypanel;
- JButton mybutton;
- JLabel mylabel;
- public static void main(String args[])
- {
- Swing first = new Swing();
- first.setTitle("First Try");
- first.setSize(300,200);
- first.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- first.setVisible(true);
- first.setLocationRelativeTo(null);
- }
- public Swing()
- {
- mypanel = new JPanel();
- mybutton = new JButton("OK");
- mybutton.addActionListener(this);
- mylabel = new JLabel();
- mypanel.add(mybutton);
- mypanel.add(mylabel);
- this.add(mypanel);
- }
- public void actionPerformed(ActionEvent event)
- {
- if(event.getSource() == mybutton)
- {
- mylabel.setText("My button clicked.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment