标签:code win 鼠标 ica end sed agg 通过 移动
KeyListener
接口方法:KeyEvent
取得。KeyEvent
事件的常用方法:package diyishiba;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.*;
public class Key implements KeyListener{
JFrame jfr=new JFrame("窗口");
JTextArea jte=new JTextArea();
JScrollPane jsc=new JScrollPane(jte,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
public Key() {
jte.addKeyListener(this);
jfr.add(jsc);
jfr.setSize(400,300);
jfr.setVisible(true);
}
public void keyTyped(KeyEvent e) {
jte.append("键盘输入的是"+e.getKeyChar()+"\n");
}
public void keyPressed(KeyEvent e) {
jte.append("键盘按下的是"+e.getKeyText(e.getKeyCode())+"\n");
}
public void keyReleased(KeyEvent e) {
jte.append("键盘松开时的是"+e.getKeyText(e.getKeyCode())+"\n");
}
}
package diyishiba;
public class test11 {
public static void main(String[] args) {
new Key();
}
}
MouseListener
接口的方法:
MouseEvent
事件的常用方法:package diyishiba;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class MouseL implements MouseListener{
JFrame jfr=new JFrame("窗口");
JTextArea jte=new JTextArea();
JScrollPane jsc=new JScrollPane(jte,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
public MouseL() {
jte.addMouseListener(this);
jfr.add(jsc);
jfr.setSize(300, 400);
jfr.setVisible(true);
}
public void mouseClicked(MouseEvent e) {
int i=e.getButton();
String j=null;
if(i==MouseEvent.BUTTON1) {
j="左键";
}
else if(i==MouseEvent.BUTTON3) {
j="右键";
}
jte.append("鼠标单击的是"+j+"\n");
}
@Override
public void mousePressed(MouseEvent e) {
// TODO 自动生成的方法存根
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO 自动生成的方法存根
}
@Override
public void mouseEntered(MouseEvent e) {
jte.append("鼠标进入文本框"+"\n");
}
@Override
public void mouseExited(MouseEvent e) {
jte.append("鼠标离开文本框"+"\n");
}
}
package diyishiba;
public class Test12 {
public static void main(String[] args) {
new MouseL();
}
}
MouseMotionListener
接口的方法:package diyishiba;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.JFrame;
public class MouseMotionL implements MouseMotionListener{
JFrame jfr=new JFrame("窗口");
public MouseMotionL() {
jfr.addMouseMotionListener(this);
jfr.setSize(400, 300);
jfr.setVisible(true);
}
@Override
public void mouseDragged(MouseEvent e) {
System.out.println("鼠标拖拽到:X="+e.getX()+",Y="+e.getY());
}
@Override
public void mouseMoved(MouseEvent e) {
System.out.println("鼠标移动到窗口");
}
}
package diyishiba;
public class Test13 {
public static void main(String[] args) {
new MouseMotionL();
}
}
JRadioButton
标签:code win 鼠标 ica end sed agg 通过 移动
原文地址:https://www.cnblogs.com/lcbxhda/p/11916951.html