第一范文网 - 专业文章范例文档资料分享平台

(含参考答案)浙江大学城市学院试卷(Java高级程序设计2010-1011-1)

来源:用户分享 时间:2025/5/19 13:09:33 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

}

}

try { Thread.sleep(100);

} catch (InterruptedException e) { e.printStackTrace(); }

taskThread.stopTask();

实现电话拨号器程序,界面如下:

设计要求如下:

设计一个MyTelephone类,该类从JFrame继承。 窗体的尺寸大小是:宽500,高300。

在主窗体的中央区域放入一个JPanel容器,该容器使用GridLayout布局,共有12个JButton按钮,各按钮排放位置如上图所示。

在主窗体的南方区域放入1个JLabel对象。 当点击按钮时,可以将点击的按钮所对应的数字填入JLabel中。比如,图中的“1338899999”就是依次点击“1”、“3”、“3”、“8”、“8”、“9”、“9”、“9”、“9”、“9”等按钮后显示的电话号码。

import java.awt.BorderLayout; import java.awt.GridLayout;

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.JPanel;

public class MyTelephone extends JFrame implements ActionListener { private JLabel numLabel = new JLabel(); public MyTelephone(){ this.setSize(500, 300); JPanel numPanel = new JPanel(); numPanel.setLayout(new GridLayout(4, 3)); JButton temp = null; for(int i = 1; i <= 9; i++){ temp = new JButton(\ temp.addActionListener(this); numPanel.add(temp); } temp = new JButton(\ temp.addActionListener(this); numPanel.add(temp); temp = new JButton(\ temp.addActionListener(this); numPanel.add(temp); temp = new JButton(\ temp.addActionListener(this); numPanel.add(temp); this.add(numPanel, BorderLayout.CENTER); this.add(numLabel, BorderLayout.SOUTH); }

}

@Override

public void actionPerformed(ActionEvent e) { numLabel.setText(numLabel.getText() + ((JButton)e.getSource()).getText()); }

public static void main(String[] args) { new MyTelephone().setVisible(true); }

(含参考答案)浙江大学城市学院试卷(Java高级程序设计2010-1011-1).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c6qo2t9l1n168ub00wtu64vbt01gdo5005e4_3.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top