import javax.swing.JButton; import javax.swing.JFrame; public class SHelloWorld { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub JFrame myframe = new JFrame("HelloWorld"); JButton mybtn = new JButton("Hello"); myframe.add(mybtn); myframe.setVisible(true); } }
import javax.swing.JButton; import javax.swing.JFrame; public class SHelloWorld { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub JFrame myframe = new JFrame("HelloWorld"); JButton mybtn = new JButton("Hello"); myframe.setBounds(100, 100, 400, 600); mybtn.setBounds(10, 10, 20, 30); myframe.add(mybtn); myframe.setVisible(true); } }
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; public class SHelloWorld { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub JFrame myframe = new JFrame("HelloWorld"); JButton mybtn = new JButton("Hello"); myframe.setBounds(100, 100, 400, 600); mybtn.setBounds(10, 10, 20, 30); mybtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub System.out.println("HelloWorld!"); System.exit(0); } }); myframe.add(mybtn); myframe.setVisible(true); } }
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; public class SHelloWorld implements ActionListener{ /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub JFrame myframe = new JFrame("HelloWorld"); JButton mybtn = new JButton("Hello"); myframe.setBounds(100, 100, 400, 600); mybtn.setBounds(10, 10, 20, 30); mybtn.addActionListener(this); myframe.add(mybtn); myframe.setVisible(true); } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub System.out.println("HelloWorld!"); System.exit(0); } }
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; public class SHelloWorld implements ActionListener{ /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub JFrame myframe = new JFrame("HelloWorld"); JButton mybtn = new JButton("Hello"); SHelloWorld me = new SHelloWorld(); myframe.setBounds(100, 100, 400, 600); mybtn.setBounds(10, 10, 20, 30); mybtn.addActionListener(me); myframe.add(mybtn); myframe.setVisible(true); } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub System.out.println("HelloWorld!"); System.exit(0); } }