import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class applet_1 extends JApplet implements ActionListener{
private int count;
JButton button1=new JButton("放大");
JButton button2=new JButton("缩小");
public void init()
{
count=1;
Container cp=getContentPane();
cp.setLayout(new GridLayout(5,3,10,10));
super.setSize(500,500);
button1.addActionListener(this);
button2.addActionListener(this);
cp.add(button1);
cp.add(button2);
}
public void actionPerformed(ActionEvent evt)
{
Object source=evt.getSource();
if(source==button1)
{
if(count==1) return;
count--;
repaint();
return;
}
if(source==button2)
{
count++;
repaint();
return;
}
}
public void paint(Graphics g)
{ if(count==1)
return;
Font font1=new Font("Default",1,count);
g.setFont(font1);
g.drawString("欢迎光临!",50,50);
}
public void start()
{ }
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class applet_1 extends JApplet implements ActionListener{
private int count;
JButton button1=new JButton("放大");
JButton button2=new JButton("缩小");
public void init()
{
count=1;
Container cp=getContentPane();
cp.setLayout(new GridLayout(5,3,10,10));
super.setSize(500,500);
button1.addActionListener(this);
button2.addActionListener(this);
cp.add(button1);
cp.add(button2);
}
public void actionPerformed(ActionEvent evt)
{
Object source=evt.getSource();
if(source==button1)
{
if(count==1) return;
count--;
repaint();
return;
}
if(source==button2)
{
count++;
repaint();
return;
}
}
public void paint(Graphics g)
{ if(count==1)
return;
Font font1=new Font("Default",1,count);
g.setFont(font1);
g.drawString("欢迎光临!",50,50);
}
public void start()
{ }
}
{
这里加super.paint(g);
if(count==1)
import java.applet.*;public class applet_1 extends JApplet implements ActionListener{
改为public class applet_1 extends Applet implements ActionListener{
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JApplet;
import javax.swing.JButton;
public class TestApplet extends JApplet implements ActionListener{
private int count=2000;
JButton button1=new JButton("放大");
JButton button2=new JButton("缩小");
public void init()
{
count=1;
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
super.setSize(500,500);
button1.addActionListener(this);
button2.addActionListener(this);
cp.add(button1);
cp.add(button2);
}
public void actionPerformed(ActionEvent evt)
{
Object source=evt.getSource();
if(source==button1)
{
if(count==2000) return;
count++;
repaint();
return;
}
if(source==button2)
{ if(count==2000) return;
count--;
repaint();
return;
}
}
public void paint(Graphics g)
{ super.paint(g);
Font font1=new Font("",1,count);
g.setFont(font1);
g.drawString("欢迎光临!",250,250);
}
public void start()
{ }
}