Java编程 设计一个图形用户界面。界面包括三个单选按钮、两个复选框、一个列表、一个文本区和一个按
Java编程设计一个图形用户界面。界面包括三个单选按钮、两个复选框、一个列表、一个文本区和一个按钮。三个单选按钮分别是回族、汉族满族。两个复选框分别是唱歌、跳舞。列表中包...
Java编程
设计一个图形用户界面。界面包括三个单选按钮、两个复选框、一个列表、一个文本区和一个按钮。三个单选按钮分别是回族、汉族满族。两个复选框分别是唱歌、跳舞。列表中包括北京、上海、天津三个列表项。按钮的标题为“确定”。要求在单选按钮、复选框和列表中进行选择,单击“确定”按钮后在文本区中显示选中的项目 展开
设计一个图形用户界面。界面包括三个单选按钮、两个复选框、一个列表、一个文本区和一个按钮。三个单选按钮分别是回族、汉族满族。两个复选框分别是唱歌、跳舞。列表中包括北京、上海、天津三个列表项。按钮的标题为“确定”。要求在单选按钮、复选框和列表中进行选择,单击“确定”按钮后在文本区中显示选中的项目 展开
展开全部
程序如下:
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
public class JFrameDemo extends JFrame implements ActionListener
{
private JPanel panel;
private JButton button;
private JTextArea textArea;
private JCheckBox musicBox;
private JCheckBox danceBox;
private JRadioButton hanButton;
private JRadioButton manButton;
private JRadioButton huiButton;
private ButtonGroup buttonGroup;
public JFrameDemo()
{
panel = new JPanel();
button = new JButton("确定");
textArea = new JTextArea(40,30);
musicBox = new JCheckBox("唱歌");
danceBox = new JCheckBox("跳舞");
huiButton = new JRadioButton("回族");
hanButton = new JRadioButton("汉族");
manButton = new JRadioButton("满族");
buttonGroup = new ButtonGroup();
buttonGroup.add(huiButton);
buttonGroup.add(hanButton);
buttonGroup.add(manButton);
panel.setLayout(new FlowLayout(3));
panel.add(huiButton);
panel.add(hanButton);
panel.add(manButton);
panel.add(musicBox);
panel.add(danceBox);
panel.add(button);
panel.add(textArea);
add(panel);
setTitle("选择兴趣爱好");
setBounds(100, 100, 400, 280);
setResizable(false);
setVisible(true);
this.button.addActionListener(this);
}
public static void main(String[] args)
{
new JFrameDemo();
}
@Override
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == this.button)
{
String info = "";
if(this.huiButton.isSelected())
{
info += this.huiButton.getText() + "\n";
}
if(this.hanButton.isSelected())
{
info += this.hanButton.getText() + "\n";
}
if(this.manButton.isSelected())
{
info += this.manButton.getText() + "\n";
}
if(this.danceBox.isSelected())
{
info += this.danceBox.getText() + "\n";
}
if(this.musicBox.isSelected())
{
info += this.musicBox.getText() + "\n";
}
this.textArea.setText(info);
}
}
}
有问题欢迎提问,满意请采纳,谢谢!
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
public class JFrameDemo extends JFrame implements ActionListener
{
private JPanel panel;
private JButton button;
private JTextArea textArea;
private JCheckBox musicBox;
private JCheckBox danceBox;
private JRadioButton hanButton;
private JRadioButton manButton;
private JRadioButton huiButton;
private ButtonGroup buttonGroup;
public JFrameDemo()
{
panel = new JPanel();
button = new JButton("确定");
textArea = new JTextArea(40,30);
musicBox = new JCheckBox("唱歌");
danceBox = new JCheckBox("跳舞");
huiButton = new JRadioButton("回族");
hanButton = new JRadioButton("汉族");
manButton = new JRadioButton("满族");
buttonGroup = new ButtonGroup();
buttonGroup.add(huiButton);
buttonGroup.add(hanButton);
buttonGroup.add(manButton);
panel.setLayout(new FlowLayout(3));
panel.add(huiButton);
panel.add(hanButton);
panel.add(manButton);
panel.add(musicBox);
panel.add(danceBox);
panel.add(button);
panel.add(textArea);
add(panel);
setTitle("选择兴趣爱好");
setBounds(100, 100, 400, 280);
setResizable(false);
setVisible(true);
this.button.addActionListener(this);
}
public static void main(String[] args)
{
new JFrameDemo();
}
@Override
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == this.button)
{
String info = "";
if(this.huiButton.isSelected())
{
info += this.huiButton.getText() + "\n";
}
if(this.hanButton.isSelected())
{
info += this.hanButton.getText() + "\n";
}
if(this.manButton.isSelected())
{
info += this.manButton.getText() + "\n";
}
if(this.danceBox.isSelected())
{
info += this.danceBox.getText() + "\n";
}
if(this.musicBox.isSelected())
{
info += this.musicBox.getText() + "\n";
}
this.textArea.setText(info);
}
}
}
有问题欢迎提问,满意请采纳,谢谢!
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询