Simple JFrame example in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fypsol.guiexamples.ex01; | |
import java.awt.FlowLayout; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import javax.swing.JButton; | |
import javax.swing.JFrame; | |
import javax.swing.JOptionPane; | |
public class MainClass { | |
public static void main(String[] args) { | |
JButton myButton = new JButton("Hello World"); | |
myButton.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
JOptionPane.showMessageDialog(myButton, "Alert", "Hello World Clicked", JOptionPane.INFORMATION_MESSAGE); | |
} | |
}); | |
JFrame mJFrame = new JFrame("My First Jframe"); | |
mJFrame.setSize(250, 150); | |
mJFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
mJFrame.setLocationRelativeTo(null); | |
// mJFrame.setLocation(400, 200); | |
mJFrame.setResizable(false); | |
mJFrame.add(myButton); | |
mJFrame.setLayout(new FlowLayout()); | |
mJFrame.setVisible(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment