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

📄 menuscibble.java

📁 Use an applet calculator procedure of the Java realization, have to have+, -, *, /function.
💻 JAVA
字号:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class MenuScibble extends Applet implements ActionListener{
	protected int lastx,lasty;
	protected int lastx1,lasty1;
	protected Color color=Color.black;
	protected PopupMenu popup;
	public void init(){
		popup=new PopupMenu("Color");
		String labels[]={"Clear","Red","Green","Blue","Black","Yellow"};
		for(int i=0;i<labels.length;i++){
			MenuItem mi=new MenuItem(labels[i]);
			mi.addActionListener(this);
			popup.add(mi);
		}
		this.add(popup);
		this.addMouseListener(new MouseAdapter(){
	    	public void mousePressed(MouseEvent e){
		    	lastx=e.getX();lasty=e.getY();
		    }
		});
		this.addMouseMotionListener(new MouseMotionAdapter(){
			public void mouseDragged(MouseEvent e){
				Graphics g=getGraphics();
				int x=e.getX(),y=e.getY();
				//g.setColor(color);
				//g.drawLine(lastx,lasty,x,y);
				g.setColor(Color.white);
				g.drawLine(lastx,lasty,lastx1,lasty1);
				g.setColor(color);
				g.drawLine(lastx,lasty,x,y);
				//try{
				//Thread.sleep(1000);
				//}catch(InterruptedException a){}	
				//g.drawLine(lastx,lasty,x,y);
		      	//g.setColor(getBackground());
			    //g.fillRect(0,0,getSize().width,getSize().height);
				lastx1=x;lasty1=y;
			}
		});
	}
	public void processMouseEvent(MouseEvent e){
		if((popup!=null)&&e.isPopupTrigger())
		    popup.show(this,e.getX(),e.getY());
		else super.processMouseEvent(e);
	}
	public void actionPerformed(ActionEvent e){
		String name=((MenuItem)e.getSource()).getLabel();
		if(name.equals("Clear")){
			Graphics g=this.getGraphics();
			g.setColor(this.getBackground());
			g.fillRect(0,0,this.getSize().width,this.getSize().height);
		}
		else if (name.equals("Red"))color=Color.red;
		else if (name.equals("Green"))color=Color.green;
		else if (name.equals("Blue"))color=Color.blue;
		else if (name.equals("Black"))color=Color.black;
		else if (name.equals("Yellow"))color=Color.yellow;
	}
}

⌨️ 快捷键说明

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