Java GUI Design Consultancy

I am programming my first Java GUI application using the Swing environment. I have encoded a basic login system using the JTextField, JPasswordField, and JButton classes. Now I am writing the actionPerformed method for the button that I want to remove, since they are no longer needed, but I'm not sure how best to achieve this.

I reviewed the use of the setVisible method of these components, which seems to work, but I'm sure this is not the most preferred way to do this. Sorry if this is a bit of a dumb question.

+3
source share
5 answers

. , .

, remove (Component) .

+5

, . , , JPanel. JPanels.

+1

JPanel , , , JPanel. , CardLayout.

. , .

.

CardLayout, :

:

static final String LOGINPANEL = "LOGINPANEL";
static final String MAINPANEL = "MAINPANEL";
JPanel cards;

:

JPanel loginPanel = new JPanel();
//add your stuff to the login panel
JPanel mainPanel = new JPanel();  
//add your stuff to the main panel

cards = new JPanel(new CardLayout());
cards.add(loginPanel, LOGINPANEL); 
cards.add(mainPanel, MAINPANEL);

, , AWT- :

CardLayout cl = (CardLayout)(cards.getLayout());
cl.show(cards, MAINPANEL);
+1

JPanel. JPanel, JPanel .

0

JDialog . "dialog.dispose()", . , , , JDesktopPane (http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JDesktopPane.html)

0

Source: https://habr.com/ru/post/1712389/


All Articles