该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
/*主类:Blue2*/
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
class DrawPane extends JTextArea{
int oldx=0,oldy=0,nowx,nowy;
DrawPane(int x,int y){
super(x,y);
this.addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent m){
oldx = m.getX();oldy = m.getY();repaint();
}});
this.addMouseMotionListener(new MouseMotionAdapter(){
public void mouseDragged(MouseEvent m){
nowx = m.getX();nowy = m.getY();repaint();
}});
this.setBackground(Color.orange);
this.setVisible(true);
}
public void paintComponent(Graphics g){
g.setColor(Color.blue);
g.drawLine(oldx,oldy,nowx,nowy);
oldx = nowx; oldy = nowy;
}
}
//拖动光标可直接在文本框中画线
class Blue2 extends JFrame{
JTextArea txtpan = new DrawPane(10,32);
Blue2(){
setBounds(100,100,560,480);
add(new JScrollPane(txtpan,22,32),BorderLayout.CENTER);
setVisible(true);
setDefaultCloseOperation(3);
}
public void paint(Graphics g){
super.paint(g);
}
public static void main(String[] ag){
new Blue2();
}
}