import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.String;
public class MouseClick
{
public static void main(String[] args)
{
//these strings will be the name of the buttons and labels
String a = new String(" who?");
String b = new String("what?");
String c = new String("when?");
//declaring the labels
Label objLabel1 = new Label(a);
objLabel1.setBounds(20,75,40,40);
Label objLabel2 = new Label(B)/>;
objLabel2.setBounds(85,120,40,40);
Label objLabel3 = new Label(c);
objLabel3.setBounds(130,185,40,40);
MouseClick MC= new MouseClick();
}
public MouseClick()
{
//frame declared
JFrame h= new JFrame("Button and labels");
//panel declared
final JPanel d = new JPanel();
//buttons declared
Button e= new Button(a);
e.setBounds(20,30,40,40);//their sizes
JButton f= new JButton(B)/>;
f.setBounds(85,75, 40, 40);
JButton g = new JButton(c);
g.setBounds(130, 120, 40, 40);
d.add(e);//add the buttons to the panel
d.add(f);
d.add(g);
h.getContentPane().add(d);//and the panel to the frame
d.add(objLabel1);//adds the labels to the panel. don't want them to be seen yet.
objLabel1.setVisible(false);
d.add(objLabel2);
objLabel2.setVisible(false);
d.add(objLabel3);
objLabel3.setVisible(false);
h.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
h.setSize(400,400);//frame settings
h.setVisible(true);
}
public class MyMouseListener extends MouseAdapter
{
public void mouseClicked(MouseEvent me)
{
objLabel1.setVisible(true);//after the mouse clicks, the labels become visible.
objLabel2.setVisible(true);
objLabel3.setVisible(true);
}
}
}
*Edited please
This post has been edited by pbl: 17 August 2012 - 06:01 AM
Reason for edit:: Code tags added

New Topic/Question
Reply




MultiQuote





|