public class JF1 extends Panel implements ActionListener{
public static void main(String[] args)
{
Frame f = new Frame();
f.setSize(200,200);
f.add( new JF1() );
f.setVisible(true);
}
public JF1(){
setup();
position();
show();
}
private Button m_switch;
private Label m_show;
private int m_type;
An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.
One of a set of tools we're offering as a way of saying thank you for being a part of the community.
Here again the whole program as it works for me. With every press to button the text changes from Thing1 to Thing2. Need some sleep now. CU and Good luck.
import java.awt.*;
import java.awt.event.*;
public class JF1 extends Panel implements ActionListener
{
//~ Instance fields --------------------------------------------------------------------------------------------------------------------
private Button m_switch;
private Label m_show;
private int m_type;
Hmmmm? I do not see any reason for this.
Whats your JDK version (java -version), platform (Windows, Linux, ...)?
My code works as listed above with the GridBagLayout. GridLayout is not so nice because it allows only a foxed grid of rows and columns.
Thanks for the points :-)
0
Question has a verified solution.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.
One of a set of tools we're offering as a way of saying thank you for being a part of the community.
Also note that I simplified your actionPerformed method slightly.
Cide wtih main:
==========================
import java.awt.*;
import java.awt.event.*;
public class JF1 extends Panel implements ActionListener{
public static void main(String[] args)
{
Frame f = new Frame();
f.setSize(200,200);
f.add( new JF1() );
f.setVisible(true);
}
public JF1(){
setup();
position();
show();
}
private Button m_switch;
private Label m_show;
private int m_type;
public void setup(){
m_switch=new Button("Switch");
m_switch.setActionCommand(
m_switch.addActionListener
m_show=new Label("Thing1");
m_type=0;
}
public void position(){
removeAll();
setLayout(new GridBagLayout());
GridBagConstraints c=new GridBagConstraints();
c.gridx=0;
c.gridy=0;
c.anchor=c.WEST;
c.insets=new Insets(10,30,0,0);
add(m_switch, c);
c.gridx=1;
add(m_show, c);
}
public void actionPerformed(ActionEven
if(e.getActionCommand().co
{
m_type ^= 1;
m_show.setText(m_type == 0 ? "Thing1" : "Thing2");
}
}
}
==========================