Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Oct 11th, 2018 58 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1.  
  2. // Java JFrame (Main Window) Testing.
  3. // Written by Techyon (Suphakorn Suttiruang)
  4.  
  5. import javax.swing.*; // Import JFrame important components.
  6.  
  7. import java.awt.*; // Java graphic components.
  8.  
  9. public class JFrameTest {
  10.  
  11.     private JFrame frame;       // Create frame variable.
  12.     private JPanel panel;       // Create panel variable.
  13.     private JButton button1;    // Create button1 variable.
  14.     private JLabel label1;      // Create label variable.
  15.    
  16.     public JFrameTest() {
  17.        
  18.         gui(); // Use gui() Method
  19.        
  20.         // Get the size of the screen
  21.         Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
  22.        
  23.         // Determine the new location of the window
  24.         int w = frame.getSize().width;
  25.         int h = frame.getSize().height;
  26.         int x = (dim.width-w)/2;
  27.         int y = (dim.height-h)/2;
  28.        
  29.         // Move the window
  30.         frame.setLocation(x, y);
  31.        
  32.     }
  33.    
  34.     public void gui() { // Declare gui() Method.
  35.        
  36.         frame = new JFrame("JFrame Testing @Techyon"); // Frame title.
  37.         frame.setVisible(true); // Set the frame to be visible.
  38.         frame.setSize(500, 400); // Set the size of the frame.
  39.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // If the frame closes, so does the program.
  40.        
  41.         panel = new JPanel(); // Declare JPanel.
  42.        
  43.         button1 = new JButton("Launch"); // Declare JButton.e
  44.         button1.setVisible(false);
  45.        
  46.         label1 = new JLabel("Here's the label."); // Declare JLabel.
  47.         label1.setForeground(Color.DARK_GRAY);
  48.        
  49.         panel.add(button1); // Add button1 to the panel.
  50.         panel.add(label1); // Add label1 to the panel.
  51.        
  52.         frame.add(panel,BorderLayout.NORTH); // Add panel to the frame.
  53.         frame.setResizable(false);
  54.     }
  55.    
  56.     public static void main(String[] args) {
  57.        
  58.         new JFrameTest();
  59.        
  60.     }
  61.  
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top