當前位置:編程學習大全網 - 編程語言 - Java編程設計了壹個圖形用戶界面。該界面包括三個單選按鈕、兩個復選框、壹個列表、壹個文本區域和壹個按鈕。

Java編程設計了壹個圖形用戶界面。該界面包括三個單選按鈕、兩個復選框、壹個列表、壹個文本區域和壹個按鈕。

該過程如下:

導入Java . awt . flow layout;

導入Java . awt . event . action event;

導入Java . awt . event . action listener;

導入javax . swing . button group;

導入javax . swing . jbutton;

導入javax . swing . jcheckbox;

導入javax . swing . jframe;

導入javax . swing . jpanel;

導入javax . swing . jradiobutton;

導入javax . swing . jtextarea;

公共類JFrameDemo擴展JFrame實現ActionListener

{

私人JPanel面板;

私有JButton按鈕;

私有JTextArea textArea

私人JCheckBox musicBox

私人JCheckBox danceBox

私有JRadioButton hanButton

私有JRadioButton manButton

私有JRadioButton huiButton

私有按鈕組按鈕組;

公共JFrameDemo()

{

panel = new JPanel();

button = new JButton(" OK ");

textArea = new JTextArea(40,30);

music box = new JCheckBox(" singing ");

dance box = new JCheckBox(" dancing ");

Hui button = new JRadioButton(" Hui ");

HanButton = new JRadioButton("漢族");

ManButton = new JRadioButton("滿語");

button group = new button group();

button group . add(hui button);

button group . add(hanButton);

button group . add(man button);

panel . set layout(new flow layout(3));

panel . add(hui button);

panel . add(hanButton);

panel . add(man button);

panel . add(music box);

panel . add(dance box);

panel.add(按鈕);

panel . add(textArea);

添加(面板);

SetTitle(“選擇壹個愛好”);

setBounds(100,100,400,280);

setResizable(false);

set visible(true);

this . button . addactionlistener(this);

}

公共靜態void main(String[] args)

{

new jframe demo();

}

@覆蓋

公共無效操作已執行(操作事件e)

{

if(e.getSource() == this.button)

{

字符串信息= " ";

if(this.huiButton.isSelected())

{

info+= this . hui button . gettext()+" \ n ";

}

if(this.hanButton.isSelected())

{

info+= this . Han button . gettext()+" \ n ";

}

if(this.manButton.isSelected())

{

info+= this . man button . gettext()+" \ n ";

}

if(this.danceBox.isSelected())

{

info+= this . dance box . gettext()+" \ n ";

}

if(this.musicBox.isSelected())

{

info+= this . music box . gettext()+" \ n ";

}

this . textarea . settext(info);

}

}

}

如果妳有任何問題,請問他們。如果妳滿意,請采納它們。謝謝大家!

  • 上一篇:人工智能考研可以報哪些學校
  • 下一篇:廣州藍弧文化傳播有限公司的主要作品簡介
  • copyright 2024編程學習大全網