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

📄 redrawallline.java

📁 java 简单的画图程序 java 简单的画图程序
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
class MyLine
{
	private int x1;
	private int y1;
	private int x2;
	private int y2;
	public MyLine(int x1,int y1,int x2,int y2)
	{
		this.x1=x1;
		this.y1=y1;
		this.x2=x2;
		this.y2=y2;
	}
	public void drawMe(Graphics g)
	{
		g.drawLine(x1,y1,x2,y2);
	}
}
public class RedrawAllLine extends Frame
{
	Vector vLines=new Vector();
	public static void main(String [] args)
	{
		RedrawAllLine f=new RedrawAllLine();
		f.init();
	}
	public void paint(Graphics g)
	{
		g.setColor(Color.red);
		Enumeration e=vLines.elements();
		while(e.hasMoreElements())
		{
			MyLine ln=(MyLine)e.nextElement();
			ln.drawMe(g);
		}
	}
	public void init()
	{
		this.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e)
			{
				((Window)e.getSource()).dispose();
				System.exit(0);
			}
			});
		addMouseListener(new MouseAdapter(){
			int orgX;
			int orgY;
			public void mousePressed(MouseEvent e)
			{
				orgX=e.getX();
				orgY=e.getY();
			}
			public void mouseReleased(MouseEvent e)
			{
				Graphics g=e.getComponent().getGraphics();
				g.setColor(Color.red);
				g.drawLine(orgX,orgY,e.getX(),e.getY());
				vLines.add(new MyLine(orgX,orgY,e.getX(),e.getY()));
			}
			});
		this.setSize(300,300);
		setVisible(true);
	}
}

⌨️ 快捷键说明

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