已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026智能健身镜用户复购率与内容订阅模式可持续性研究报告
- 2026中国自行车行业市场分析及发展趋势与投资前景预测研究报告
- 2026智慧零售行业发展分析及商业模式创新与投资价值研究报告
- 2026 年国航货运物流板块央企紧缺人才综合考核试卷 招录 63 人
- 2026中国智能智能洗衣机洁净系统行业市场供需分析及投资评估规划分析研究报告
- 2026年ICU CTA 检查监护护理试卷及答案
- 2026年FLACC 疼痛量表儿科应用试卷及答案
- 2026年c语言期末考试试题及答案
- 2026实木复合板行业技术突破与市场前景研究报告
- 2026年cdfi考试试题及答案
- 眼科疾病诊疗技术新进展与挑战
- 高校实验室建设项目投标文件
- 2026北京市市政工程设计研究总院有限公司校园招聘笔试历年参考题库
- 标准预防知识培训课件
- 《规模化公猪站常温精液生产全过程质控技术规范》征求意见稿
- 2025年中级消防题库试卷及答案
- 2025年国家公务员考录《行测》真题及参考答案
- 《数据中心综合布线技术规程》
- (高清版)DZT 0073-2016 电阻率剖面法技术规程
- 凯撒大帝3行人规律的秘密
- 计算机科学与技术专业导论课程教学大纲
评论
0/150
提交评论