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

📄 ex2.java

📁 java课程的资料以及实验的代码
💻 JAVA
字号:
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.math.*;


class color extends Frame implements MouseListener,MouseMotionListener,WindowListener
{
	Label l1,l2;
	TextField t1;
	int r,g,b;
	Color cc;
	public color()
	{
		this.setSize(300,300);
		this.setLayout(new GridLayout(2,1));
		
		Panel p1=new Panel();
		p1.setLayout(new GridLayout(1,2));
		
		l1=new Label("");
		l1.addMouseMotionListener(this);
		l1.addMouseListener(this);
		l2=new Label("color");
		l2.addMouseListener(this);
		l2.addMouseMotionListener(this);
		
		t1=new TextField();
		t1.addMouseMotionListener(this);
		
		p1.add(l2);
		p1.add(t1);
		
		this.add(l1);
		this.add(p1);
		
		this.addWindowListener(this);
		this.setVisible(true);
	}
	
	
	public static void main(String[] args)
	{
		color c=new color();
	}
	
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		if((e.getModifiers() & MouseEvent.META_MASK)!=0)
		{
			l1.setText("变色龙");
		}
		else if((e.getModifiers() & e.META_MASK)==0)
		{
			l1.setText("");
		}
	}

	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		if(e.getSource()==l2)
		{
			if(t1.getText().equalsIgnoreCase("blue"))
			{
				l2.setBackground(Color.blue);
			}
			else if(t1.getText().compareToIgnoreCase("pink")==0)
			{
				l2.setBackground(Color.pink);
			}
		}
	}

	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		l2.setBackground(Color.red);
	}

	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}


	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}


	public void mouseMoved(MouseEvent e) {
		// TODO Auto-generated method stub
		r=e.getX()%256;
		g=e.getY()%256;
		b=(e.getX()+e.getY())%256;
		cc=new Color(r,g,b);
		l1.setBackground(cc);
	}


	public void windowActivated(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}


	public void windowClosed(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}


	public void windowClosing(WindowEvent e) {
		// TODO Auto-generated method stub
		System.exit(1);
	}


	public void windowDeactivated(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}


	public void windowDeiconified(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}


	public void windowIconified(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}


	public void windowOpened(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}
	
}

⌨️ 快捷键说明

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