




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 18653-2025胎儿弯曲杆菌的分离鉴定方法
- GB/T 46092-2025海上设施用单点系泊索
- 2025年零售行业无人商店发展前景分析研究报告
- 2025年科技行业人工智能应用前景分析报告
- 2025年生物技术行业市场前景预测研究报告
- 2025年医疗科技行业健康科技应用前景研究报告
- 2025年零售连锁行业无人超市发展前景研究报告
- 商场保洁员培训课件
- 威海市2025山东威海市文登区招考劳务派遣制书记员12人笔试历年参考题库附带答案详解
- 国家事业单位招聘2025中国疾病预防控制中心(中国预防医学科学院)教育培训处(研究生院)招笔试历年参考题库附带答案详解
- 中学物理实验室安全管理制度
- 沂沭泗河洪水东调南下续建工程南四湖湖东堤工程施工组织设计
- 制鞋工艺流程
- 土石方工程运输合同
- 国际伤口治疗师汇报
- 《电工基础(第2版)》中职全套教学课件
- 河道清淤与水生态恢复方案
- 2024-2025大学英语考试六级汉译英中英对照
- 铂类化疗药物配置
- 2024-2025学年广东省深圳实验学校高中园高一(上)第一次段考数学试卷(含答案)
- 2024-2025学年天津市和平区双菱中学七年级(上)第一次月考数学试卷
评论
0/150
提交评论