java GUI编程的一个完整的实例
4个回答
展开全部
package Exam_5;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
@SuppressWarnings("serial")
public class exam_5_1 extends Applet implements ActionListener
{
private Button bt1,bt2;
int button=0;
public void init()
{
bt1=new Button("B-ONE");
bt2=new Button("B-TWO");
add(bt1);
add(bt2);
bt1.addActionListener(this);
bt2.addActionListener(this);
}
public void paint(Graphics g)
{
if(button==1)
g.drawString("You press the B-one", 10, 30);
else if(button==2)
g.drawString("You press the B-two", 10, 30);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("B-ONE"));
button=1;
if(e.getActionCommand().equals("B-TWO"));
button=2;
repaint();
}
}
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
@SuppressWarnings("serial")
public class exam_5_1 extends Applet implements ActionListener
{
private Button bt1,bt2;
int button=0;
public void init()
{
bt1=new Button("B-ONE");
bt2=new Button("B-TWO");
add(bt1);
add(bt2);
bt1.addActionListener(this);
bt2.addActionListener(this);
}
public void paint(Graphics g)
{
if(button==1)
g.drawString("You press the B-one", 10, 30);
else if(button==2)
g.drawString("You press the B-two", 10, 30);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("B-ONE"));
button=1;
if(e.getActionCommand().equals("B-TWO"));
button=2;
repaint();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Java程序:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test35 extends JFrame implements ItemListener{
private static final long serialVersionUID = 1L;
JComboBox cmbGender;
JLabel lblMessage;
public Test35(){
super("工业09");
String[] arr = new String[];
cmbGender = new JComboBox(arr);
lblMessage = new JLabel("请选择你的性别");
this.setLayout(new FlowLayout());
this.add(lblMessage);
this.add(cmbGender);
cmbGender.addItemListener(this);
this.setSize(200, 100);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new Test35();
}
@Override
public void itemStateChanged(ItemEvent e) {
JComboBox cmb = (JComboBox)e.getSource();
if(cmb == cmbGender){
lblMessage.setText(cmb.getSelectedItem().toString());
}
}
}
运行测试:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test35 extends JFrame implements ItemListener{
private static final long serialVersionUID = 1L;
JComboBox cmbGender;
JLabel lblMessage;
public Test35(){
super("工业09");
String[] arr = new String[];
cmbGender = new JComboBox(arr);
lblMessage = new JLabel("请选择你的性别");
this.setLayout(new FlowLayout());
this.add(lblMessage);
this.add(cmbGender);
cmbGender.addItemListener(this);
this.setSize(200, 100);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new Test35();
}
@Override
public void itemStateChanged(ItemEvent e) {
JComboBox cmb = (JComboBox)e.getSource();
if(cmb == cmbGender){
lblMessage.setText(cmb.getSelectedItem().toString());
}
}
}
运行测试:
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
童鞋,自己看书吧。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-09-07
展开全部
去网上下载呀 特别多。。。推荐电驴
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |