Home > Back-end >  How do you write a beginner, this empty
How do you write a beginner, this empty

Time:09-29

Import the Java. The awt. *;
Import the Java. The awt. Event. An ActionEvent;
Import the Java. The awt. Event. ActionListener;
Import the Java. The awt. Event. MouseListener;
Import the Java. Beans. EventHandler;

The import javax.mail. Swing. JButton;
import javax.swing.JFrame;
The import javax.mail. Swing. JLabel;
The import javax.mail. Swing. JPanel;
Public class AdapterTest extends JFrame implements ActionListener {
int x,y;
String STR.
JButton b;
JLabel l;
Public AdapterTest () {
Super (" The Mouse Adapeter ");
GetContentPane (). SetLayout (new FlowLayout ());
JPanel p=new JPanel ();
L=new JLabel (" both Please click the window ");
GetContentPane (). The add (l);
B=new JButton (" Quit ");
B.a ddActionListener (this);
GetContentPane (). The add (b);
ListenerClass listen=new ListenerClass ();
B.a ddMouseListener (listen);
SetSize (300300);
setVisible(true);
}
Public void actionPerformed (an ActionEvent e) {
String s=um participant etActionCommand ();
If (" Quit ". The equals (s)) {
System.exit(0);
}
}
Public static void main (String [] args) {
AdapterTest f=new AdapterTest ();
}


}
Import the Java. The awt. Event. MouseAdapter;

The import org. W3c. Dom. The Text;

The import com. Sun. Glass. Events. MouseEvent;
The import com. Sun. XML. Internal. Ws. Server. Sei. EndpointResponseMessageBuilder. DocLit;


Public class ListenerClass extends MouseAdapter {
Public void mouseClicked MouseEvent (me) {
AdapterTest at=;//get the event source object
Palawan l.s etText (" Mouse clicked at: "+ me. GetX () +", "+ me. GetY ());
}

}
  • Related