First of all, I don't know how to put this straight and correctly, so bear with my lack of valuable information. Anyhow, I've just started learning Java GUI today and it seems pretty amusing and somewhat simple(if it comes to the basics such as creating a window with objects), yet there are obstacles. What I'm trying to do here is make a simple GUI that containts 2 label, 2 text fields and a button. The 2 lables are X and Y, with respective fields to enter a desired text. The button is used to "concatinate" the entries and add them to a different label then show it in a seperate panel. My code is:
public class Fenetre extends JFrame
{
private JPanel p;
private JPanel jpanel;
public JLabel etiq1, etiq2, etiqr;
public JTextField text1;
public JTextField text2;
public JButton button1;
public Fenetre()
{
super();
setLayout(new GridLayout());
this.setSize(300,300);
this.setVisible(true);
this.setContentPane(this.getContentPane());
this.setTitle("X+Y résultat");
jpanel=(JPanel)this.getContentPane();
text1=new JTextField();
text2=new JTextField();
etiq1=new JLabel("X");
etiq2=new JLabel("Y");
jpanel.add(etiq1);
jpanel.add(etiq2);
jpanel.add(text1);
jpanel.add(text2);
button1=new JButton("X+Y");
this.add(button1);
this.pack();
jpanel.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
etiqr.setText(text1.getText()+text2.getText());
}
});
}
}
What I've made so far is the window that contains the objects and a mouseListener to concatinate the two texts into a single one. My question is how do I use the mouseListener to show the concatinated text in a different panel?(Supposdly in the same frame?).