2011-09-05 7 views
1

이 프로그램을 실행하는 방법은 무엇입니까?JFrame 프로그램을 실행하십시오

// Resolve class BorderLayout 
import java.awt.*; 
// Resolve class JFrame and JButton 
import javax.swing.*; 
// Definition of class FrameWithBorderLayout 

public class FrameWithBorderLayout extends JFrame {// Attribute 

    private JButton buttonEast; // The east button 
    private JButton buttonSouth; // The south button 
    private JButton buttonWest; // The west button 
    private JButton buttonNorth; // The north button 
    private JButton buttonCenter; // The center button 
    // Constructor 

    public FrameWithBorderLayout() { 
     // Call super class constructor with a title 
     super("Frame With Multiple Buttons"); 
     // Create JButton objects 
     buttonEast = new JButton("East"); 
     buttonSouth = new JButton("South"); 
     buttonWest = new JButton("West"); 
     buttonNorth = new JButton("North"); 
     buttonCenter = new JButton("Center"); 
     // Add the JButton objects 
     add(buttonEast, BorderLayout.EAST); 
     add(buttonSouth, BorderLayout.SOUTH); 
     add(buttonWest, BorderLayout.WEST); 
     add(buttonNorth, BorderLayout.NORTH); 
     add(buttonCenter, BorderLayout.CENTER); 
     // Set when the close button is clicked, the application exits 
     setDefaultCloseOperation(EXIT_ON_CLOSE); 
     // Reorganize the embedded components 
     pack(); 
    } 
} 

--------------------------------- 현재 소스 -------- -----------------------------

// Resolve class BorderLayout 
import java.awt.*; 
// Resolve class JFrame and JButton 
import javax.swing.*; 
// Definition of class FrameWithBorderLayout 
public class test extends JFrame { 

// Attribute 
    private JButton buttonEast; // The east button 
    private JButton buttonSouth; // The south button 
    private JButton buttonWest; // The west button 
    private JButton buttonNorth; // The north button 
    private JButton buttonCenter; // The center button 
// Constructor 
    public test() { 
    // Call super class constructor with a title 
     super("Frame With Multiple Buttons"); 
     // Create JButton objects 
     buttonEast = new JButton("East"); 
     buttonSouth = new JButton("South"); 
     buttonWest = new JButton("West"); 
     buttonNorth = new JButton("North"); 
     buttonCenter = new JButton("Center"); 
     // Add the JButton objects 
     add(buttonEast, BorderLayout.EAST); 
     add(buttonSouth, BorderLayout.SOUTH); 
     add(buttonWest, BorderLayout.WEST); 
     add(buttonNorth, BorderLayout.NORTH); 
     add(buttonCenter, BorderLayout.CENTER); 
     // Set when the close button is clicked, the application exits 
     setDefaultCloseOperation(EXIT_ON_CLOSE); 
     // Reorganize the embedded components 
     pack(); 
    } 
    public static void main(String[] args) { 
     java.awt.EventQueue.invokeLater(new Runnable() { 
       public void run() { 
        FrameWithBorderLayout frame = new FrameWithBorderLayout(); 
        frame.setVisible(true); 
       } 
     }); 
    } 
} 

답변

12

모든 자바 프로그램이 주요 방법에서 시작 :

public static void main(String[] args) { 
    java.awt.EventQueue.invokeLater(new Runnable() { 
      public void run() { 
       FrameWithBorderLayout frame = new FrameWithBorderLayout(); 
       frame.setVisible(true); 
      } 
    }); 
} 

프레임 클래스에 추가하십시오.

+0

실행 : 스레드 예외 "주요"java.lang.RuntimeException가 : Uncompilable 소스 코드 - <익명의 테스트 $ 1>은 추상적하지 않고 java.lang.Runnable의 \t에 추상 메소드 실행()를 오버라이드 (override)하지 않습니다Java 결과 : 1 성공한 빌드 (총 시간 : 1 초) – hkguile

+0

@hkinterview - 내 최신 대답을보십시오. –

+0

실행 : 스레드 "AWT-EventQueue-0"예외가 발생했습니다. "java.lang.RuntimeException : 컴파일 할 수없는 소스 코드 - 심볼 심볼을 찾을 수 없음 symbol : class FrameWithBorderLayout \t, 테스트 $ 1.run (te st.java:37) java.awt.event.InvocationEvent.dispatch (InvocationEvent.java:251) java.awt.EventQueue.dispatchEventImpl에서 \t (EventQueue.java:705)에서 \t java.awt.EventQueue에서 \t .access $ 000 (EventQueue.java:101) java.awt.EventQueue $의 3.run에서 \t (EventQueue.java:666) java.awt.EventQueue $의 3.run에서 \t (EventQueue.java:664) 자바에서 \t .security.AccessController.doPrivileged (네이티브 메서드) – hkguile

0
FrameWithBorderLayout frameTest = new FrameWithBorderLayout(); 
frameTest.setVisible(true); 
+0

내 netbeans에서 FrameWithBorderLayout 아래에 빨간색 테두리가 있습니다. – hkguile

관련 문제