日期:2014-05-20 浏览次数:20611 次
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import java.awt.event.MouseListener;
import java.awt.Toolkit;
public class Wmain{
public static void main(String[] args){
JFrame myjf=new testchress();
}
}
public class testchress extends JFrame implements MouseListener {
public testchress(){
this.setVisible(true);
this.setTitle("我是标题");
this.setSize(300,200);//窗口宽300,高200
this.setLocation(400,400);
int width=Toolkit.getDefaultToolkit().getScreenSize().width;//获取屏幕宽度
int height=Toolkit.getDefaultToolkit().getScreenSize().height;//获取屏幕高度
this.setLocation((width-200)/2,(height-200)/2);
this.addMouseListener(this);
}
public void mouseClicked(MouseEvent e){
System.out.println("你单击了");
JOptionPane.showMessageDialog(this, "你单击了内容");
}
public void mousePressed(MouseEvent e){
System.out.println("你按下了键");
}
public void mouseReleased(MouseEvent e){
System.out.println("抬起了");
}
/**
* 进入事件
*/
public void mouseEntered(MouseEvent e){
}
//鼠标移出事件
public void mouseExited(MouseEvent e){
}
}
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.Toolkit;
public class Wmain{
public static void main(String[] args){
JFrame myjf=new testchress();
}
}
class testchress extends JFrame implements MouseListener {