Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make a button show other buttons and options.
    primarykey
    data
    text
    <p>I am trying to create program where you can press one of the buttons on the first page and it will open more buttons and labels and such. But I'm not sure how to make it so that when the button is pressed it will show those other buttons and labels. </p> <p>The code is </p> <pre><code>public class Japp extends JApplet implements ActionListener{ private JPanel panel1= new JPanel(); private JPanel panel2= new JPanel(); JPanel container = new JPanel(); //container.setLayout(new BoxLayout(container, BoxLayout.X_AXIS)); JButton reg = new JButton ("Register"); JButton log = new JButton ("Login"); JLabel regusrlbl = new JLabel ("Enter Username"); JLabel regpwdlbl = new JLabel ("Enter Password"); JLabel regpwdconlbl = new JLabel ("Confirm Username"); JTextField regusr = new JTextField(""); JTextField regpwd = new JTextField(""); JTextField regpwdcon = new JTextField(""); JButton create = new JButton("Create"); JLabel logusrlbl = new JLabel ("Enter Username"); JLabel logpwdlbl = new JLabel ("Enter Password"); JTextField logusr = new JTextField(""); JTextField logpwd = new JTextField(""); JButton login = new JButton("Login"); public void init(){ setLayout(null); add(reg).setBounds(50,100,100,30); add(log).setBounds(150,100,100,30); } @SuppressWarnings("deprecation") public void actionPerformed(ActionEvent e) { JButton source = (JButton)e.getSource(); if (source.getLabel()=="reg"){ // TODO Auto-generated method stub remove(reg); remove(log); add(regusrlbl).setBounds(20,20, 150,50); add(regusr).setBounds(20,50,100,30); add(regpwdlbl).setBounds(200,20,150,50); add(regpwd).setBounds(200,50,100,30); add(regpwdconlbl).setBounds(195,80,150,30); add(regpwdcon).setBounds(200,110,100,30); add(create).setBounds(110,140,100,30); // setup all the context... } else if(source.getLabel()=="log"){ remove(reg); remove(log); add(logusrlbl).setBounds(20,20, 150,50); add(logusr).setBounds(20,50,100,30); add(logpwdlbl).setBounds(200,20,150,50); add(logpwd).setBounds(200,50,100,30); add(login).setBounds(110,140,100,30); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload