Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Java JFrame (Main Window) Testing.
- // Written by Techyon (Suphakorn Suttiruang)
- import javax.swing.*; // Import JFrame important components.
- import java.awt.*; // Java graphic components.
- public class JFrameTest {
- private JFrame frame; // Create frame variable.
- private JPanel panel; // Create panel variable.
- private JButton button1; // Create button1 variable.
- private JLabel label1; // Create label variable.
- public JFrameTest() {
- gui(); // Use gui() Method
- // Get the size of the screen
- Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
- // Determine the new location of the window
- int w = frame.getSize().width;
- int h = frame.getSize().height;
- int x = (dim.width-w)/2;
- int y = (dim.height-h)/2;
- // Move the window
- frame.setLocation(x, y);
- }
- public void gui() { // Declare gui() Method.
- frame = new JFrame("JFrame Testing @Techyon"); // Frame title.
- frame.setVisible(true); // Set the frame to be visible.
- frame.setSize(500, 400); // Set the size of the frame.
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // If the frame closes, so does the program.
- panel = new JPanel(); // Declare JPanel.
- button1 = new JButton("Launch"); // Declare JButton.e
- button1.setVisible(false);
- label1 = new JLabel("Here's the label."); // Declare JLabel.
- label1.setForeground(Color.DARK_GRAY);
- panel.add(button1); // Add button1 to the panel.
- panel.add(label1); // Add label1 to the panel.
- frame.add(panel,BorderLayout.NORTH); // Add panel to the frame.
- frame.setResizable(false);
- }
- public static void main(String[] args) {
- new JFrameTest();
- }
- }
Add Comment
Please, Sign In to add comment