Доработав еще этот кусок, у меня опять возникла похожая проблема, объясните в чем проблема, и как сделать чтоб следующее работало:
| Код | public class TestMain { public static void main(String[] args) { TestFrame frame = new TestFrame(); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } public class TestFrame extends JFrame { private static int frameMaxSizeX, frameMaxSizeY; public TestFrame(){ setTitle("Super Test :)"); Toolkit toolkit = Toolkit.getDefaultToolkit(); frameMaxSizeX = (int) toolkit.getScreenSize().getWidth(); frameMaxSizeY = (int) toolkit.getScreenSize().getHeight();
setBounds(frameMaxSizeX / 4, frameMaxSizeY / 4, frameMaxSizeX / 2, frameMaxSizeY / 2);
TextPanel textPanel = new TextPanel(); ButtonPanel buttonPanel = new ButtonPanel(); buttonPanel.textPanel = textPanel; buttonPanel.testFrame = this; add(textPanel, BorderLayout.CENTER); add(buttonPanel, BorderLayout.SOUTH);
} public static int getFrameMaxSizeX() { return frameMaxSizeX; }
public static int getFrameMaxSizeY() { return frameMaxSizeY; } } public class TextPanel extends JPanel { public String status; private JTextField fieldName, fieldSurname, fieldPatronymic;
private JLabel welcome = new JLabel(); private JPanel panelName = new JPanel(), panelSurname = new JPanel(), panelPatronymic = new JPanel();
public JTextField getFieldName() { return fieldName; }
public JTextField getFieldSurname() { return fieldSurname; }
public JTextField getFieldPatronymic() { return fieldPatronymic; }
public TextPanel() {
addWelcome("WELCOME"); }
public void addFIO() { fieldName = new JTextField(""); fieldName.setFocusable(true); fieldName.setPreferredSize(new Dimension(200, 20)); fieldName.setMaximumSize(new Dimension(200, 20)); fieldName.setMinimumSize(new Dimension(200, 20));
JLabel labelName = new JLabel("Name: "); panelName.setVisible(true); panelName.add(labelName, BorderLayout.CENTER); panelName.add(fieldName, BorderLayout.CENTER); panelName.setPreferredSize(new Dimension(TestFrame.getFrameMaxSizeX(), 30));
fieldSurname = new JTextField(""); fieldSurname.setFocusable(true); fieldSurname.setPreferredSize(new Dimension(200, 20)); fieldSurname.setMaximumSize(new Dimension(200, 20)); fieldSurname.setMinimumSize(new Dimension(200, 20));
JLabel labelSurname = new JLabel("Surname: "); panelSurname.setVisible(true); panelSurname.add(labelSurname, BorderLayout.CENTER); panelSurname.add(fieldSurname, BorderLayout.CENTER); panelSurname.setPreferredSize(new Dimension(TestFrame.getFrameMaxSizeX(), 30));
fieldPatronymic = new JTextField(""); fieldPatronymic.setFocusable(true); fieldPatronymic.setPreferredSize(new Dimension(200, 20)); fieldPatronymic.setMaximumSize(new Dimension(200, 20)); fieldPatronymic.setMinimumSize(new Dimension(200, 20));
JLabel labelPatronymic = new JLabel("Patronymic:"); panelPatronymic.setVisible(true); panelPatronymic.add(labelPatronymic, BorderLayout.CENTER); panelPatronymic.add(fieldPatronymic, BorderLayout.CENTER); panelPatronymic.setPreferredSize(new Dimension(TestFrame.getFrameMaxSizeX(), 30));
JLabel intro = new JLabel("Hi, please enter your information :)");
add(intro, BorderLayout.CENTER); add(panelName, BorderLayout.CENTER); add(panelSurname, BorderLayout.CENTER); add(panelPatronymic, BorderLayout.CENTER); getLayout().layoutContainer(this); repaint(); }
public void hideFIO(){ panelName.setVisible(false); panelSurname.setVisible(false); panelPatronymic.setVisible(false); }
public void addWelcome(String test) { status = Constants.WELCOME; welcome.setText("<html><h1>" + test + "</h1></html>"); welcome.setVisible(true); add(welcome, BorderLayout.CENTER); getLayout().layoutContainer(this); repaint(); }
public void hideWelcome() { welcome.setVisible(false); } } public class ButtonPanel extends JPanel { public TextPanel textPanel; public TestFrame testFrame;
public ButtonPanel() { JButton next = new JButton("Next"); next.setPreferredSize(new Dimension(70, 20)); next.setMaximumSize(new Dimension(70, 20)); next.setMinimumSize(new Dimension(70, 20)); next.setFocusable(false); next.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (textPanel.status.equals(Constants.WELCOME)) { textPanel.hideWelcome(); textPanel.status = "1"; } else { textPanel.addFIO(); } } }); JButton exit = new JButton("Exit"); exit.setPreferredSize(new Dimension(70, 20)); exit.setMaximumSize(new Dimension(70, 20)); exit.setMinimumSize(new Dimension(70, 20)); exit.setFocusable(false); add(next, BorderLayout.WEST); add(exit, BorderLayout.WEST); } } public class Constants { public static String WELCOME = "Welcome"; public static String INTRODUCTION= "Welcome"; }
|
Сейчас просто добавлено, что после первого нажатия исчезает надпись велкам, после второго появляются Labels с текством и поля ввода текста, поля ввода не появляются... Заранее спасибо |