Skip to content

Instantly share code, notes, and snippets.

@bc080401210
Created January 18, 2019 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bc080401210/72d870f024d40e98ede6b643e2dca853 to your computer and use it in GitHub Desktop.
Save bc080401210/72d870f024d40e98ede6b643e2dca853 to your computer and use it in GitHub Desktop.
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() {
@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