标签:gety value vax ola char awt png 代码 struct
工具:eclipse
语言:java
成果:
源代码:
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionAdapter;
import javax.swing.JFrame;
import javax.swing.JPanel;
class HuiTu{
JFrame mFrame=new JFrame("画板");
JPanel mPanel=new JPanel();
int LastX=0;
int LastY=0;
public HuiTu() {
// TODO Auto-generated constructor stub
mFrame.setSize(800, 800);
mFrame.setVisible(true);
mFrame.setForeground(Color.BLUE);
mFrame.add(mPanel);
mPanel.setBackground(Color.WHITE);
mFrame.addMouseListener(new MouseAdapter() {
public void mousePress(MouseEvent e) {
LastX = e.getX();
LastY = e.getY();
}
});
mFrame.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
int x=e.getX();
int y=e.getY();
Graphics g =mFrame.getGraphics();
g.drawLine(LastX, LastY, x, y);
LastX=e.getX();
LastY=e.getY();
}
});
mFrame.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
String string=String.valueOf(e.getKeyChar());
mFrame.getGraphics().drawString(string, LastX, LastY);
LastX += 30;
}
});
}
}
public class C5T8 {
public static void main(String[] args) {
// TODO Auto-generated method stub
new HuiTu();
}
}
标签:gety value vax ola char awt png 代码 struct
原文地址:https://www.cnblogs.com/huchangqing/p/8996410.html