2017-11-04 15 views
0

이 코드를 실행하려고하면 실행 콘솔에서 작업이 종료되었다는 메시지가 나타나지만 코드에 오류가없고 모든 것이 잘 보입니다.자바 splitpane 도움말 코드가 실행될 때 종료합니다

public class Component1 extends JFrame 
{ 
    public Component1() { 

     setTitle("GUI"); 
     setSize(150, 150); 

     //The code below creates the two panels of the UI And they are both labelled with names. 
     JPanel jsp1 = new JPanel(); 
     JPanel jsp2 = new JPanel(); 
     JLabel j1 = new JLabel("Left Side"); 
     JLabel j2 = new JLabel("Right Side"); 

     //jsp1 and jsp2 work together with the code above to create the two panels of the interface by adding "J1" and "J2" this allows 
     //both sides to be labelled and appear on the UI   

     jsp1.add(j1); 
     jsp2.add(j2); 

     JSplitPane splitPane = new 
JSplitPane(JSplitPane.HORIZONTAL_SPLIT, 
      true, jsp1, jsp2); 

     splitPane.setOneTouchExpandable(true); 
     getContentPane().add(splitPane); 
    } 

    public static void main(String[] args) 
    { 
     Component1 sp = new Component1(); 
     sp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     sp.setVisible(true); 
    } 
    Component1panel panel = new Component1panel(); 
} 

답변

0

main()이 종료되면 응용 프로그램을 종료합니다. 프레임을 보유하고있는 스레드를 시작해야합니다. (필요한 경우 수정 수입)

이에 주 편집을 ​​시도해보십시오

또한
public static void main(String[] args){ 
    javax.swing.SwingUtilities.invokeLater(new Runnable() { 
     public void run() { 

      // build and show your GUI    

      Component1 sp = new Component1(); 
      sp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
      sp.setVisible(true); 
     } 
    }); 
} 

, 어쩌면 JFrame 안녕하세요 세계에 대한 링크가 도움이 될 것입니다 조언을 link

+1

감사합니다, 내 코드 보인다 지금 일하고있어, 고마워. –

+0

도와 줘서 기쁩니다. 행운을 빌어 요 프로그래밍. 다음은 java docs 링크입니다. https://docs.oracle.com/javase/tutorial/uiswing/components/frame.html –