2012-04-21 2 views
-1

클래스가 있고 다른 클래스에있는 프레임 (NetBeans의 디자이너로 만든)을로드하려고합니다. 내가 어떻게해야하지?프레임에서 다른 클래스에있는 다른 프레임으로 이동

public class Champs1 extends javax.swing.JFrame { 

/** 
* Creates new form Champs1 
*/ 
public Champs1() { 
    initComponents(); 
} 

/** 
* This method is called from within the constructor to initialize the form. 
* WARNING: Do NOT modify this code. The content of this method is always 
* regenerated by the Form Editor. 
*/ 
@SuppressWarnings("unchecked") 
// <editor-fold defaultstate="collapsed" desc="Generated Code"> 
private void initComponents() { 

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 
    setTitle("COMBAT SIMULATOR"); 
    setMaximumSize(new java.awt.Dimension(640, 480)); 
    setMinimumSize(new java.awt.Dimension(640, 480)); 
    setResizable(false); 

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 
    getContentPane().setLayout(layout); 
    layout.setHorizontalGroup(
     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     .addGap(0, 640, Short.MAX_VALUE) 
    ); 
    layout.setVerticalGroup(
     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     .addGap(0, 480, Short.MAX_VALUE) 
    ); 

    pack(); 
}// </editor-fold> 

/** 
* @param args the command line arguments 
*/ 
public static void main(String args[]) { 
    /* 
    * Set the Nimbus look and feel 
    */ 
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> 
    /* 
    * If Nimbus (introduced in Java SE 6) is not available, stay with the 
    * default look and feel. For details see 
    * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
    */ 
    try { 
     for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { 
      if ("Nimbus".equals(info.getName())) { 
       javax.swing.UIManager.setLookAndFeel(info.getClassName()); 
       break; 
      } 
     } 
    } catch (ClassNotFoundException ex) { 
     java.util.logging.Logger.getLogger(Champs1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    } catch (InstantiationException ex) { 
     java.util.logging.Logger.getLogger(Champs1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    } catch (IllegalAccessException ex) { 
     java.util.logging.Logger.getLogger(Champs1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    } catch (javax.swing.UnsupportedLookAndFeelException ex) { 
     java.util.logging.Logger.getLogger(Champs1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    } 
    //</editor-fold> 

    /* 
    * Create and display the form 
    */ 
    java.awt.EventQueue.invokeLater(new Runnable() { 

     public void run() { 
      new Champs1().setVisible(true); 
     } 
    }); 
} 
// Variables declaration - do not modify 
// End of variables declaration 

} 내가로드 할 프레임을 보유하고있는 클래스에있어 무엇

.

+0

당신이 [JFrames 사용하는 방법에 대한 섹션]을 포함하여 스윙 튜토리얼을 겪었 (http://docs.oracle.com/ javase/tutorial/uiswing/components/frame.html) 아직? 이 과정에서 어떤 부분을 고집하고 있습니까? 당신이 만든 수업을 말하는 변수를 만드는 법을 이해하고 있습니까? –

+0

아니, 사실, 난 그냥 거기에서 몇 가지 자습서를 읽지 않았다. 임 봐야 겠어;) – Kevin04PT

답변

0

는 내가 제대로 이해 있는지 확실하지 않습니다,하지만 난 노력 할게요 : 자바 프레임이 전체 창뿐만 아니라 그 내용이다

첫째 주. 따라서 다른 프레임을로드하면 새 창이 열릴 것입니다. 이 같은 자바에서이 작업을 수행 할 수 있습니다

new NameOfOtherFrameClass().setVisible(true); 

난 당신이 몇 가지 튜토리얼을 읽고 "손으로"간단한 무언가를 코딩하려고하면 일이 명확 얻을 것이라고 생각한다 (즉, 넷빈즈없이 디자이너).

더 나은 대답을 얻으려면 프레임을로드하거나 원하는 작업과 Java 기술이 무엇인지 의미하는 것이 무엇인지 설명해야합니다.

+0

실제로 대답을 주셔서 감사합니다. 대답은 매우 간단합니다. – Kevin04PT

+0

학교 프로젝트를 위해 자바로 프로그래밍을 시작했기 때문에 나의 자바 기술은 매우 기본적이고, 실제로 사용되지는 않았습니다. 내가 의미하는 바를 설명하는 방식으로 ... 그리고 네, NetBeans 디자이너를 사용하지 않고 좀 더 간단한 코드를 작성해야한다고 말한 것은 맞습니다. – Kevin04PT

+0

@ Kevin04PT 자바를 처음 접한다면 GUI 프로그래밍을 시작하지 않아야합니다. 자바에서는 그렇게 쉽지가 않습니다. 나는 당신이'System.out'에 무언가를 쓰고, 루프 ('for','while'), 조건 ('if')으로 시작하는 것이 가장 좋다라고 생각합니다 ... 시작이 어렵고 지루할 수도 있지만, 계속합니다. 기초와 자바를 배우는 것은 재미있을 것입니다! :-) – siegi

0

일부 작업 (예 : 버튼을 클릭하는 동안)을 수행하는 동안 다른 클래스를 호출 할 수 있습니다. 그래서, 버튼이나 다른 컴포넌트를 만들고 나서, 메소드를 구현하십시오.이 클래스에서는, 클래스의 오브젝트를 지정해, 거기로부터 메소드를 호출 할 수 있습니다.

편집 : 참조 용

:

JButton test_button=new JButton(new AbstractAction("Test") { 
      @Override 
      public void actionPerformed(ActionEvent e) { 
       Test test=new Test();   // Make Object of class which you want to call 
       test.showMessage();    //Any method that you might want to call 
      } 
     }); 
+0

그리고 실제로 그렇게했습니다. actionPerformed 메서드가있는 버튼이지만 작동하도록하려면 어떻게해야하는지 잘 모릅니다 ... 이해가 확실하지 않습니다. – Kevin04PT

+0

@ Kevin04PT : 이해를 돕기 위해 내 대답을 편집했습니다. – Parth

관련 문제