




已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第一题:import javax.swing.JFrame;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Fahrenheit /* * param args */public static void main(String args) / TODO Auto-generated method stubJFrame frame = new JFrame(Fahrenheit);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);FahrenheitPanel panel = new FahrenheitPanel();frame.getContentPane().add(panel);frame.pack();frame.setVisible(true);class FahrenheitPanel extends JPanelprivate JLabel inputLabel,outputLabel,resultLabel;private JButton OK;private JTextField fahrenheit;public FahrenheitPanel()inputLabel = new JLabel(Enter Fahrenheit temperature:);outputLabel = new JLabel(Temperature in Celsius:);resultLabel = new JLabel(-);OK = new JButton (OK!);fahrenheit = new JTextField(5);fahrenheit.addActionListener(new TempListener();OK.addActionListener(new TempListener();add(inputLabel);add(fahrenheit);add(outputLabel);add(resultLabel);add(OK);setPreferredSize (new Dimension(300,75);setBackground(Color.green);private class TempListener implements ActionListener public void actionPerformed (ActionEvent event)int fahrenheitTemp,celsiusTemp;String text = fahrenheit.getText();fahrenheitTemp = Integer.parseInt(text);celsiusTemp = (fahrenheitTemp-31)*5/9;resultLabel.setText(Integer.toString(celsiusTemp);第二题:import javax.swing.JFrame;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Random /* * param args */public static void main(String args) JFrame frame = new JFrame(Random game );frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);RandomPanel panel = new RandomPanel();frame.getContentPane().add(panel);frame.pack();frame.setVisible(true);class RandomPanel extends JPanelprivate JLabel resultLabel;private int randomNumber;private JButton OK;public RandomPanel()resultLabel = new JLabel(-); OK= new JButton(确定!);OK.addActionListener(new ButtonListener();add(resultLabel);add(OK);setPreferredSize(new Dimension(300,100);setBackground(Color.blue);private class ButtonListener implements ActionListenerprivate final int BASE = 100;public void actionPerformed(ActionEvent event)String result = (you get:+randomNumber);randomNumber=(int)(Math.random()*BASE+1);resultLabel.setText(result);第三题:import java.awt.*;import java.awt.event.*;import javax.swing.*;public class UpDownpublic static void main(String args) JFrame frame=new JFrame(ChangeData ); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new ChangeData() ); frame.pack(); frame.setVisible(true);class ChangeData extends JPanel /* * */private int count;private JButton up,down;private JLabel label;private JPanel buttonPanel;public ChangeData()count=50;up=new JButton(Up);down=new JButton(Down);up.addActionListener(new ButtonListener();down.addActionListener(new ButtonListener();label=new JLabel(data: +count);buttonPanel=new JPanel();buttonPanel.setPreferredSize(new Dimension(300,40);buttonPanel.setBackground(Color.red);buttonPanel.add(up);buttonPanel.add(down);setPreferredSize(new Dimension(300,60);setBackground(Color.green);add(label);add(buttonPanel);public class ButtonListener implements
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 创新金融工具在粮食安全保障中的应用前景
- 产学研合作模式促进艺术学理论人才创新能力培养
- 2025至2030中国骑行服市场营销渠道与供求平衡预测分析报告
- 辽宁省辽阳市二中学教育协作2025届九上化学期末质量跟踪监视模拟试题含解析
- 湖南省株洲市荷塘区2024年七上数学期末复习检测模拟试题含解析
- 内蒙古自治区通辽市奈曼旗2024年化学九年级第一学期期末联考试题含解析
- 2025至2030中国景观设计行业市场深度调研及竞争格局与投资发展潜力报告
- 吉林省长春宽城区四校联考2024-2025学年八年级物理第一学期期末预测试题含解析
- 餐饮商铺租赁及品牌孵化合同
- 医疗设备质量管理实践案例分析
- 中风脑梗死恢复期中医护理方案课件
- 新生儿重症监护室母乳使用专家共识(2024版)解读
- 病毒性脑炎诊疗指南(儿科)
- 乐器设备供货项目实施方案及售后服务方案
- 中共党史知识竞赛试题及答案
- 2020年杭州学军中学高一入学分班考试英语试卷及答案
- (高清版)AQ 1044-2007 矿井密闭防灭火技术规范
- 死亡医学证明书填写培训
- 做自己的心理压力调节师智慧树知到期末考试答案章节答案2024年嘉兴大学
- 学术期刊推广方案
- 安检设备采购安装调试方案
评论
0/150
提交评论