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

📄 shiyan5.java

📁 本人在JAVA学习中的一点小实验
💻 JAVA
字号:
//<applet code="shiyan5.class" height="150" width="300">
//</applet> 
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
class MyPanel extends JPanel{
	int size =20;    
	Font f =new Font("SansSerif",Font.BOLD,size);
	public void paintComponent(Graphics g){
	 	super.paintComponent(g);
	 	String s="I love java";
	 	g.setFont(f);
	 	g.setColor(Color.RED);
	 	g.drawString(s,50,50);	
	 	
		}	
	}   
public class shiyan5 extends JApplet  implements ActionListener{
	   JButton jbutton1;
	   JButton jbutton2;
	   MyPanel mp=new MyPanel();

	  public void init(){
	    jbutton1=new JButton("放大");
	    jbutton2=new JButton("缩小");
	    
	    JPanel jpanel=new JPanel();
	 	FlowLayout layout=new FlowLayout();
	 	jpanel.setLayout(layout);
	 	jpanel.add(jbutton1);
	 	jpanel.add(jbutton2);
                
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(jpanel,BorderLayout.SOUTH);
        getContentPane().add(mp,BorderLayout.CENTER);
	    jbutton1.addActionListener(this);
		jbutton2.addActionListener(this);
		
		
		
	}
	
	public void actionPerformed(ActionEvent e) {
	if(e.getSource()==jbutton1)
	{ mp.size = mp.size+2; 	
	  mp.f = new Font("SansSerif",Font.BOLD,mp.size);
	  mp.repaint();
	}
	if(e.getSource()==jbutton2)
	{  mp.size = mp.size-2;
	   mp.f = new Font("SansSerif",Font.BOLD,mp.size);	
	   mp.repaint();
	 }
	        
	    } 	
}	 	

⌨️ 快捷键说明

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