




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 遗传性肾癌VHL综合征型护理查房
- 特发性肺纤维化合并呼吸衰竭护理查房
- 阿尔山市2025-2026学年八年级下学期语文月考测试试卷
- 安徽省淮北市相山区2024-2025学年高一上学期第二次月考物理试题及答案
- 2025 年小升初忻州市初一新生分班考试英语试卷(带答案解析)-(外研版)
- 2025 年小升初衡水市初一新生分班考试数学试卷(带答案解析)-(冀教版)
- 工程热力学及内燃机原理2012年7月自考试题
- 甘肃省白银十中2024-2025学年八年级下学期期末物理试卷(含答案)
- 进口药品销售合同范本
- 别墅改造租房合同范本
- 新能源汽车产业股权并购及供应链整合协议
- 疼痛的基本概念及诊断
- 阴阳五行与健康课件
- 2025中国南水北调集团新能源投资有限公司中层及职员社会招聘笔试参考题库附带答案详解
- office办公软件培训课件
- DB64∕ 266-2018 建筑工程资料管理规程
- 高中地理开学第一课高一上学期
- 1《中国人民站起来了》公开课一等奖创新教学设计统编版高中语文选择性必修上册
- 中学团建活动方案
- 注射并发症及其处理
- 神经外科症状护理
评论
0/150
提交评论