编写一个Applet程序(JAVA)
3个回答
展开全部
import java.awt.*;
import java.awt.event.*;
class Test
{
static Frame f= new Frame();
static Label l = new Label();
static Button b = new Button("按钮");
static TextArea tb = new TextArea();
public static void main(String[] args) {
f.setSize(300,300);
f.setLocation(100,100);
f.setVisible(true);
f.add(l,"North");
f.add(tb,"Center");
f.add(b,"South");
l.setText("标签");
tb.setText("文本框");
l.setVisible(true);
b.setVisible(true);
tb.setVisible(true);
f.pack();
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
b.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
l.setText(tb.getText());
}
});
}
}
import java.awt.event.*;
class Test
{
static Frame f= new Frame();
static Label l = new Label();
static Button b = new Button("按钮");
static TextArea tb = new TextArea();
public static void main(String[] args) {
f.setSize(300,300);
f.setLocation(100,100);
f.setVisible(true);
f.add(l,"North");
f.add(tb,"Center");
f.add(b,"South");
l.setText("标签");
tb.setText("文本框");
l.setVisible(true);
b.setVisible(true);
tb.setVisible(true);
f.pack();
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
b.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
l.setText(tb.getText());
}
});
}
}
展开全部
//here it is
import java.awt.Color;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class SimpleApplet extends JApplet {
private JButton button = new JButton("Click me");
private JTextField field = new JTextField("Hello");
private JLabel label = new JLabel();
public void init() {
Container con = this.getContentPane();
con.setLayout(new GridLayout(3, 1));
con.setSize(400, 100);
label.setForeground(Color.RED);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
label.setText(field.getText());
}
});
con.add(label);
con.add(field);
con.add(button);
}
public void start() {
this.setVisible(true);
}
private static final long serialVersionUID = 1L;
}
import java.awt.Color;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class SimpleApplet extends JApplet {
private JButton button = new JButton("Click me");
private JTextField field = new JTextField("Hello");
private JLabel label = new JLabel();
public void init() {
Container con = this.getContentPane();
con.setLayout(new GridLayout(3, 1));
con.setSize(400, 100);
label.setForeground(Color.RED);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
label.setText(field.getText());
}
});
con.add(label);
con.add(field);
con.add(button);
}
public void start() {
this.setVisible(true);
}
private static final long serialVersionUID = 1L;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
最新方法,效率第一
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.border.BevelBorder;
public class XXX {
private JTextField textField;
private JFrame frame;
/**
* Launch the application
*
* @param args
*/
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
XXX window = new XXX();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application
*/
public XXX() {
createContents();
}
/**
* Initialize the contents of the frame
*/
private void createContents() {
frame = new JFrame();
frame.getContentPane().setLayout(null);
frame.setBounds(100, 100, 500, 375);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JButton button = new JButton();
button.setText("New JButton");
button.setBounds(43, 50, 106, 28);
frame.getContentPane().add(button);
final JLabel Label = new JLabel();
Label.setBorder(new BevelBorder(BevelBorder.LOWERED));
Label.setBounds(61, 146, 66, 18);
frame.getContentPane().add(Label);
textField = new JTextField();
textField.setBounds(212, 144, 87, 22);
frame.getContentPane().add(textField);
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg0) {
String str = textField.getText();
if (str.equals("")) {
javax.swing.JOptionPane.showMessageDialog(XXX.this.frame,
"文本框为空");
} else {
Label.setText(str);
}
}
});
}
}
最新方法,效率第一
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.border.BevelBorder;
public class XXX {
private JTextField textField;
private JFrame frame;
/**
* Launch the application
*
* @param args
*/
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
XXX window = new XXX();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application
*/
public XXX() {
createContents();
}
/**
* Initialize the contents of the frame
*/
private void createContents() {
frame = new JFrame();
frame.getContentPane().setLayout(null);
frame.setBounds(100, 100, 500, 375);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JButton button = new JButton();
button.setText("New JButton");
button.setBounds(43, 50, 106, 28);
frame.getContentPane().add(button);
final JLabel Label = new JLabel();
Label.setBorder(new BevelBorder(BevelBorder.LOWERED));
Label.setBounds(61, 146, 66, 18);
frame.getContentPane().add(Label);
textField = new JTextField();
textField.setBounds(212, 144, 87, 22);
frame.getContentPane().add(textField);
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg0) {
String str = textField.getText();
if (str.equals("")) {
javax.swing.JOptionPane.showMessageDialog(XXX.this.frame,
"文本框为空");
} else {
Label.setText(str);
}
}
});
}
}
最新方法,效率第一
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询