JAVA 프로그래밍 - Helloworld Swing Center
// 컴퓨터공학과 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();
}
});
}
}
'Univ Study > JAVA 프로그래밍' 카테고리의 다른 글
JAVA 프로그래밍 - NumberAddition V3 Event Handling (0) | 2010.02.15 |
---|---|
JAVA 프로그래밍 - NumberAddition V2 Layout Manager (0) | 2010.02.15 |
JAVA 프로그래밍 - NumberAddition V1 Swing GUI (0) | 2010.02.15 |
JAVA 프로그래밍 - Helloworld Swing Center (0) | 2010.02.15 |
JAVA 프로그래밍 - Helloworld Swing (0) | 2010.02.15 |
JAVA 프로그래밍 - Hello World (0) | 2010.02.15 |