2010-11-27 7 views
0

テキストフィールドに「シャットダウン」を追加するには フレーム4のbutton22を押すとフレーム5を終了できますか?別のフレームにテキストを追加する

JButton jButton22 = new JButton(); 
    JButton jButton23 = new JButton(); 
    JButton jButton24 = new JButton(); 

    public Frame4() { 
    try { 
     jbInit(); 
    } 
    catch(Exception e) { 
     e.printStackTrace(); 
    } 
    } 
    private void jbInit() throws Exception { 
    titledBorder1 = new TitledBorder(""); 
    border1 = BorderFactory.createLineBorder(new Color(164, 225, 164),2); 
    border2 = BorderFactory.createLineBorder(new Color(164, 225, 164),2); 
    border3 = BorderFactory.createLineBorder(new Color(94, 85, 50),2); 
    this.getContentPane().setBackground(new Color(63, 138, 232)); 
    this.setSize(new Dimension(400, 345)); 
this.setLocation(150,150); 
    this.getContentPane().setLayout(null); 
    jPanel1.setBackground(new Color(211, 229, 250)); 
    jPanel1.setBorder(border3); 
    jPanel1.setBounds(new Rectangle(4, 47, 389, 193)); 
    jPanel1.setLayout(null); 
    jLabel1.setFont(new java.awt.Font("Dialog", 0, 30)); 
    jLabel1.setForeground(new Color(255, 137, 27)); 
    jLabel1.setAlignmentY((float) 0.5); 
    jLabel1.setText("  server side ®™"); 
    jLabel1.setBounds(new Rectangle(-44, 0, 314, 54)); 
    jLabel2.setFont(new java.awt.Font("Dialog", 1, 15)); 
    jLabel2.setForeground(new Color(60, 193, 60)); 
    jLabel2.setText("status is connected"); 
    jLabel2.setBounds(new Rectangle(107, 11, 165, 31)); 
    jLabel4.setBounds(new Rectangle(252, 160, 124, 42)); 
    jButton20.addActionListener(new java.awt.event.ActionListener() { 
     public void actionPerformed(ActionEvent e) { 
     jButton20_actionPerformed(e); 
     } 
    }); 

    jButton22.addActionListener(new java.awt.event.ActionListener() { 
     public void actionPerformed(ActionEvent e) { 
     jButton22_actionPerformed(e); 

     } 
    }); 

    jButton23.addActionListener(new java.awt.event.ActionListener() { 
     public void actionPerformed(ActionEvent e) { 
     jButton23_actionPerformed(e); 
     } 
    }); 

    jButton24.addActionListener(new java.awt.event.ActionListener() { 
     public void actionPerformed(ActionEvent e) { 
     jButton24_actionPerformed(e); 
     } 
    }); 


    void jButton20_actionPerformed(ActionEvent e) { 
new Frame3().setVisible(true); 
this.setVisible(false); 
    } 
    void jButton21_actionPerformed(ActionEvent e) { 
System.exit(0); 
    } 
    void jButton22_actionPerformed(ActionEvent e) { 

    new Frame5().setVisible(true); 


this.setVisible(false); 
    } 
    void jButton23_actionPerformed(ActionEvent e) { 
    new Frame5().setVisible(true); 
this.setVisible(false); 
    } 
    void jButton24_actionPerformed(ActionEvent e) { 
    new Frame5().setVisible(true); 
this.setVisible(false); 
    } 
} 
+0

コードを選択してCtrl + Kキーを押してコードをフォーマットしてください。プレビューを使用します。 – EboMike

+0

意味のある変数名を使用してください。 – palAlaa

+0

自動生成...嫌いです...あなたのIDEに問い合わせてください – khachik

答えて

0

あなたの質問はちょっと混乱しています。
あなたの質問は、現在のフレームから別のフレームのテキストフィールドのテキストを変更することだと思います。
そうなら、関数を使うだけで簡単に実行できます。たとえば、
frame4とframe5の2つのフレームがある場合、frame4にはボタン(たとえばbutton4)が含まれ、frame5にはテキストフィールド(たとえばjtextfield)が含まれています。

frame4のbutton4をクリックすると、frame5のjtextfieldのテキストを変更します。
、等frame5の関数を書く

公共ボイド変化(文字列テキスト)フレーム4からテキストを変更するためのその後{

jtextfield.setText(テキスト)

}

その関数を "change"と呼ぶだけです。.ie、

frame5 f = new frame5();
f.change( "シャットダウン");

ここで、「シャットダウン」は追加するテキストです。

+1

これは問題なく動作します。 –

関連する問題