Skip to content

Instantly share code, notes, and snippets.

Created January 18, 2019 14:25
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Simple JFrame example in Java
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() {
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.setLocation(400, 200);
mJFrame.setLayout(new FlowLayout());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment