编写一个Java的小程序Applet

import java.applet.*;public class Try extends Applet implements ActionListener { public void init(){ Button b=new Button("请按按钮");b.addActionListener(this);add(b);} public void actionPerformed(ActionEvent e){ Frame f=new Frame("警告");f.setSize(200,100);f.setLocation(300...
编写一个Java的小程序Applet
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Try extends Applet implements ActionListener
{
public void init()
{
Button b=new Button("请按按钮");
b.addActionListener(this);
add(b);
}
public void actionPerformed(ActionEvent e)
{
Frame f=new Frame("警告");
f.setSize(200,100);
f.setLocation(300,300);
f.add(new Label("你按了按钮!"));
f.setVisible(true);
}

}2008-12-27
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class MyApplet extends JApplet {
public MyApplet() {
}

public void init(){
myFont = new Font("Dialog",Font.BOLD,16);
Bigger = new JButton("BIGGER");
Smaller = new JButton("Smaller");
jPanel1 = new JPanel();
jPanel2 = new JPanel();
jLabel1 = new JLabel("This is a Applet test!!");
jLabel1.setFont(myFont);
jPanel1.setLayout(new FlowLayout());
jPanel1.add(Bigger);
jPanel1.add(Smaller);
jPanel2.add(jLabel1);

Container cp= this.getContentPane();
cp.setLayout(new BorderLayout());
cp.add(jPanel1,BorderLayout.SOUTH);
cp.add(jPanel2,BorderLayout.CENTER);

Bigger.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt) {
BiggerActionPerformed(evt);
}
});

Smaller.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt) {
SmallerActionPerformed(evt);
}
});

this.setVisible(true);
}

private void BiggerActionPerformed(ActionEvent evt){
int size = myFont.getSize()+2;
myFont = new Font("Dialog",Font.BOLD,size);
this.jLabel1.setFont(myFont);
}

private void SmallerActionPerformed(ActionEvent evt){
int size = myFont.getSize()-2;
myFont = new Font("Dialog",Font.BOLD,size);
this.jLabel1.setFont(myFont);
}

private JButton Bigger,Smaller;
private JPanel jPanel1,jPanel2;
private JLabel jLabel1;
private Font myFont;
}

<html>
<head>
<title>Java</title>
</head>

<body>
<applet code="MyApplet.class" width="160" height="140"></applet>
</body>
</html>

换一个2008-12-27
mengvlog 阅读 388 次 更新于 2025-12-16 03:11:12 我来答关注问题0
檬味博客在线解答立即免费咨询

Java相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部