0
我試圖做一個嚮導而不使用庫,我見過很容易使巫術師哈哈它的一個項目,我做了佈局和框架和麪板,有什麼麻煩是當我點擊「 - >」它不會去panel2,什麼也沒有發生,它確實存儲了名稱,但是這是它。有人能幫我嗎?ActionListener從Jpanel調用另一個Jpanel
編輯它現在的作品:)現在我有麻煩顯示第二個「panel2」它後,我沒有成爲什麼後,我點擊箭頭。笑
package project4;
import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class WizardGUI extends JFrame implements ActionListener {
private JLabel enterName;
private JTextField name;
private JButton prev, fow;
private String storeName = "";
WizardGUI(){
super("Wizard");
name();
}
void name()
{
JPanel FPanel = new JPanel();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new FlowLayout());
// JLabel textLabel = new JLabel("lol");
//textLabel.setPreferredSize(new Dimension(300, 100));
// frame.getContentPane().add(textLabel);
//prev = new JButton("<--");
fow = new JButton ("-->");
this.add(FPanel);
enterName = new JLabel("Enter Your Name: ");
name = new JTextField(10);
enterName.setBounds(60, 30,120,30);
name.setBounds(80,60,130,30);
this.setSize(300,390); //set frame size
this.setVisible(true);
FPanel.add(enterName);
FPanel.add(name);
//FPanel.add(prev);
FPanel.add(fow);
fow.addActionListener(this);
}
void enter()
{
JPanel panel2 = new JPanel();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new FlowLayout());
//prev = new JButton("<--");
fow = new JButton ("-->");
this.add(panel2);
enterName = new JLabel("Enter Your Name: ");
name = new JTextField(10);
enterName.setBounds(60, 30,120,30);
name.setBounds(80,60,130,30);
this.setSize(300,390); //set frame size
this.setVisible(true);
panel2.add(enterName);
panel2.add(name);
//FPanel.add(prev);
panel2.add(fow);
fow.addActionListener(this);
this.getContentPane().removeAll();
validate();
repaint();
this.add(panel2);
}
void add()
{
}
void select()
{
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == fow) {
storeName = name.getText();
enter();
//JOptionPane.showMessageDialog(null, "hello " + storeName);
}
}
}
謝謝:)
謝謝!使它工作我也把內容放在框架上而不是面板上。啊!! :) – Rafa579
+1尤其對於超級構造函數的提及。 :) – brimborium