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

📄 driver.java

📁 可随机画出位置形状均不相同的直线
💻 JAVA
字号:
import java.awt.*;
import javax.swing.JFrame;
import java.awt.event.*;
public class driver extends JFrame
{
    private JFrame window;
    private line line1;
    private oval oval1;
    private rect rect1;
    public driver() 
    {
    	window = new JFrame("PAINT A RAND SHAPE");
    	
    	int length=(int)(100*Math.random());
    	window.setBounds(length,length,length+200,length+200);
    	window.setVisible(true);
    	window.setLayout(null);
    	window.setBackground(Color.white);
    	
    	int chosen=(int)(10*Math.random())%3;
    	int slength=length-(int)(length*(float)Math.random());
    	switch (chosen)
    	{
    	
    		case 0:
    			line1=new line();
    			line1.setBounds(slength,slength,slength+(int)(50*(1-(float)Math.random())),slength+(int)(50*(1-(float)Math.random())));
    			line1.setBackground(Color.black);
    			window.add(line1,0);
    			break;
    		case 1:
    			oval1=new oval();
    			oval1.setBounds(slength,slength,slength+(int)(50*(1-(float)Math.random())),slength+(int)(50*(1-(float)Math.random())));
    			oval1.setBackground(Color.black);
    			window.add(oval1,0);
    			break;
    		case 2:
    			rect1=new rect();
    			rect1.setBounds(slength,slength,slength+(int)(50*(1-(float)Math.random())),slength+(int)(50*(1-(float)Math.random())));
    			rect1.setBackground(Color.black);
    			window.add(rect1,0);
    	}
    	window.repaint(); 			
    }
    public static void main(String args[])
    {
    	driver dr=new driver();
    	dr.addWindowListener(
    		new WindowAdapter()
    		{
    			public void windowClosing(WindowEvent windowEvent)
    			{
    				System.exit(0);
    			}
    		}    		
    	);	
    }
}

⌨️ 快捷键说明

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