Tools: Eclipse
Language: Java
Results:
Source:
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 (" artboard ");
JPanel Mpanel=new JPanel ();
intlastx=0;
intlasty=0;
Public Huitu () {
// TODO auto-generated constructor stub
mframe. SetSize (+);
mframe. setvisible (true);
mframe. Setforeground (Color. BLUE );
mframe. Add (mpanel);
Mpanel. SetBackground (Color. White );
mframe. Addmouselistener (new mouseadapter () {
Public voidmousepress (MouseEvent e) {
lastx = e. GetX ();
lasty = e. GetY ();
}
});
mframe. Addmousemotionlistener (new mousemotionadapter () {
Public void mousedragged (MouseEvent e) {
intx=e. GetX ();
inty=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 + = +;
}
});
}
}
Public class c5t8 {
Public staticvoid main (string[] args) {
// TODO auto-generated method stub
New Huitu ();
}
}
Java to do a mouse drawing, keyboard to write the artboard