⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swing3.java

📁 《Java编程基础、应用与实例》 源文件下载
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Random;
public class Swing3 extends JFrame{
  int ox, oy;
  Random rnd = new Random();
  Swing3(String title){
    super(title);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getContentPane().setBackground(Color.white);
    addMouseListener(new MouseAdapter(){
      public void mousePressed(MouseEvent me){
        ox=me.getX(); oy=me.getY();
      }
    });
    addMouseMotionListener(new MouseMotionAdapter(){
      public void mouseDragged(MouseEvent me){
        int x= me.getX(), y=me.getY();
        Graphics g=getGraphics();
        g.setColor(new Color(rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256)));
        g.drawLine(ox, oy, x, y);
        ox=x; oy=y;
      }
    });
  }
  
  public static void main(String[] args) throws Exception{
    JFrame f=new Swing3("胶喇");
    f.setSize(300, 300);
    f.setVisible(true);
  }
}
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -