编写一个Java的小程序Applet
编写一个Java的小程序Applet要求:体现Applet中的用户交互功能,有动作的监听,例如用户进行按钮的选择,程序给出相应的动作。不要那么长,简单一点就可以了....
编写一个Java的小程序Applet要求:体现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);
}
}
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);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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>
换一个
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>
换一个
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询