如何编写一个java applet
发布网友
发布时间:2022-05-26 10:58
我来回答
共1个回答
热心网友
时间:2023-10-14 03:20
import java.applet.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class jj extends Applet //implements ActionListener
{
JLabel l1;
JLabel l2;
JTextField t1;
JTextField t2;
JButton button; public void init()
{
resize(1000,70);
l1=new JLabel("请输入单词:");
t1=new JTextField(10);
l1=new JLabel("大写的单词为:");
t2=new JTextField(10);
button=new JButton("大写");
l1.setFont(new Font("宋体",Font.BOLD,30));
l1.setForeground(Color.green);
t1.setFont(new Font("宋体",Font.BOLD,30));
t1.setForeground(Color.black);
t2.setFont(new Font("宋体",Font.BOLD,30));
t2.setForeground(Color.blue);
button.setFont(new Font("宋体",Font.BOLD,30));
button.setForeground(Color.black);
l2.setFont(new Font("宋体",Font.BOLD,30));
l2.setForeground(Color.red);// btn.addActionListener(this); this.add(l1);
this.add(t1);
this.add(button);
this.add(l2);
this.add(t2);
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button)
{
String str=t1.getText().toUpperCase();
t2.setText(str);
}
}
});
}}