解析JAVA程序设计第六章课后答案(2)

2019-08-30 16:43

boolean flag;

MainPanel()

{

Panel ScreenPanel = new Panel(); //Screen Panel

ScreenPanel.setLayout(new BorderLayout());//Screen in the north

ScreenPanel.add(scn,BorderLayout.CENTER);

scn.disable(); //can not receive event

Panel ButtonPanel = new Panel(); //Button Panel

ButtonPanel.setLayout(new GridLayout(4,4));

for (int i=0;i<16;i++)

{

btn[i]=new Button(str[i]); //new Button

ButtonPanel.add(btn[i]); //add to panel

}

Panel ButtonPane2 = new Panel(); //Button Panel

ButtonPane2.add(clear);

setLayout(new BorderLayout()); //Main panel

add(ScreenPanel,BorderLayout.NORTH);

add(ButtonPanel,BorderLayout.CENTER);

add(ButtonPane2,BorderLayout.SOUTH);

}

}

class CountFrame extends Frame //construct a frame {

public CountFrame(String title)

{

super(title);

MainPanel t=new MainPanel(); //Main Panel

add(t); //add MainFrame

addWindowListener(new end()); //add listener

}

class end extends WindowAdapter //close the window,inner class

{

public void windowClosing(WindowEvent e)

{

System.exit(0);

}

}

}

class Count //main() {

public static void main(String args[])

{

CountFrame frm=new CountFrame(\计算器\

frm.setSize(220,180); //new frame,go above

frm.show();

} }

程序的运行结果为:

7.试设计一个电话簿程序的界面。

//PhoneBook.java

import javax.swing.*;

import java.awt.*;

public class PhoneBook extends JFrame {

void go()

{

this.setTitle(\电话簿程序\

this.setSize(400,200);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Container contentPane = this.getContentPane();

String[] data = {\张三\李四\赵二\王五\

JList dataList = new JList(data);

dataList.setSelectedIndex(1); // select \

dataList.getSelectedValue(); // returns \

JPanel p1=new JPanel();

JPanel p2=new JPanel();

JPanel p3=new JPanel();

p1.setSize(200,400);

contentPane.add(p1,BorderLayout.WEST);

contentPane.add(p2,BorderLayout.CENTER);

contentPane.add(p3,BorderLayout.SOUTH);

p1.add(dataList);

p2.setLayout(new GridLayout(6,1));

JLabel l1=new JLabel(\姓名:\

JTextField t1=new JTextField(\李四\

JLabel l2=new JLabel(\联系电话:\

JTextField t2=new JTextField(\

p2.add(l1);

p2.add(t1);

p2.add(l2);

p2.add(t2);

p3.add(new JButton(\添加\

p3.add(new JButton(\删除\

p3.add(new JButton(\修改\

this.show();

}

public static void main(String[] g) {

PhoneBook h=new PhoneBook();

h.go(); } }

8.为6和7题的添加事件处理功能。

第6题加事件处理:

//Count.java


解析JAVA程序设计第六章课后答案(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:公安机关组织管理机构改革初探(修改后3)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: