Univ Study/JAVA 프로그래밍: 7개의 글

JAVA 프로그래밍 - NumberAddition V1 Swing GUI

Posted by Patchman
2010.02.15 18:49 Univ Study/JAVA 프로그래밍


// 컴퓨터공학과 3학년 안치영

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.BorderFactory;
import java.awt.BorderLayout;

public class NumberAddtionV1 {

  /* Constructor */
 public NumberAddtionV1(){
    
  // (1) Create and set up the window.
  JFrame frame = new JFrame("NumberAddtionV1");
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
     // (2) Create a main panel.
   JPanel mainPanel = new JPanel();
 
     // (3) Add widgets onto the main panel.
  addWidgets(mainPanel);
   
     // (4) Add the main panel to Content Pane
  frame.getContentPane().add(mainPanel);
 
     // (5) Display the window.
  CenterScreen cs = new CenterScreen();
  frame.setLocation(cs.getX(frame), cs.getY(frame));
  frame.pack();
  frame.setVisible(true);
 }

 private void addWidgets(JPanel mainPanel){

   // TextField
   JTextField TextFirst = new JTextField(10);
   JTextField TextSecond = new JTextField(10);
   JTextField TextThird = new JTextField(10);

    // Label
   JLabel LabelFirst = new JLabel("First Number : ");
   JLabel LabelSecond = new JLabel("Second Number : ");
   JLabel LabelThird = new JLabel("Result : ");

    // Button
   JButton ButtonAdd = new JButton("Add");
   JButton ButtonClear = new JButton("Clear");
   JButton ButtonExit = new JButton("Exit");

  
    mainPanel.add(LabelFirst);
    mainPanel.add(TextFirst);

    mainPanel.add(LabelSecond);
    mainPanel.add(TextSecond);

    mainPanel.add(LabelThird);
    mainPanel.add(TextThird);

    mainPanel.add(ButtonAdd);
    mainPanel.add(ButtonClear);
    mainPanel.add(ButtonExit);
 }

 private static void createAndShowGUI(){
  NumberAddtionV1 h = new NumberAddtionV1();
 }
 
    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}

JAVA 프로그래밍 - Helloworld Swing Center

Posted by Patchman
2010.02.15 18:47 Univ Study/JAVA 프로그래밍


// 컴퓨터공학과 3학년 안치영

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.*;

public class HelloWorldSwingCenter {
    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
    private static void createAndShowGUI() {
        /* Create and set up the window. */
        JFrame frame = new JFrame("HelloWorldSwingCenter");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setSize(250, 80);

  Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); // 현재 시스템 화면의 크기 구하기
  Dimension f_size = frame.getSize(); // 생성 프레임의 크기 구하기

  int x = (int)(screen.getWidth()/2 - f_size.getWidth()/2); // 시스템 화면의 중앙 넓이
  int y = (int)(screen.getHeight()/2 - f_size.getHeight()/2); // 시스템 화면의 중앙 높이

  frame.setLocation(x , y);

        /* Add the ubiquitous "Hello World" label. */
        JLabel label = new JLabel("Hello World", SwingConstants.CENTER);
        frame.getContentPane().add(label);


        /* Display the window. */
  //frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}

JAVA 프로그래밍 - Helloworld Swing

Posted by Patchman
2010.02.15 18:46 Univ Study/JAVA 프로그래밍


 

// 컴퓨터공학과 3학년 안치영

import javax.swing.*;       

public class HelloWorldSwing {
    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("HelloWorldSwing");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Add the ubiquitous "Hello World" label.
        JLabel label = new JLabel("Hello World");
        frame.getContentPane().add(label);

        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}