实验八 图形用户界面与对话框

更新时间:2024-03-30 11:03:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

实验八 图形用户界面与对话框

1. 实验目的

1、学会处理ActionEvent事件 2、学会使用布局类

3、学习焦点、鼠标和键盘事件 4、学习使用输入和消息对话框

2. 实验内容

1、根据附录里的源代码,按照注释要求,完成代码填空,使程序能够运行得出结果。

1) 实验1算术测试 2) 实验2布局与日历 3) 实验3华容道 4) 实验4字体对话框 5) 实验5计算平方根 6) 实验6简易计算器

2、设计编写程序完成以下任务。

1)修改实验1的代码,再增加“小学生”级别,并增加测试乘、除法的功能。

2)编写一个应用程序,用户可以在一个文本框里输入数字字符,按Enter

键后将数字放入一个文本区。当输入的数字大于1000时,弹出一个有模式的对话框,提示用户数字已经大于1000,是否继续将该数字放入文本区。

3)编写应用程序,有一个标题为“移动”的窗口,窗口布局为null,

在窗口中有两个按钮,单击一个按钮让另一个按钮移动。

4)仿照操作系统中的简易计算机,自行设计一个能进行加减乘除运算的

计算器。需要考虑先进性乘除运算再进行加减运算。

3. 实验步骤

4. 评分标准

1. A——内容功能完善,编程风格好,人机接口界面好; 2. B——内容功能完善,编程风格良好,人机接口界面良好; 3. C——完成必做内容; 4. D——能完成必做内容;

5. E——未按时完成必做内容,或者抄袭(雷同者全部为E).

参照书上实验按模版要求,将【代码】替换为Java程序代码,编写好完整的程序文档,最后运行得到的相关文件,把实验所得文件一起打包上交。(压缩包的文件名为:学号后三位和名字开头字母,如109zhh.RAR|ZIP)

附录: 实验1 算术测试

模板代码 Teacher.java

import java.util.Random; import java.awt.event.*; import javax.swing.*;

public class Teacher implements ActionListener{

int numberOne,numberTwo; String operator=\boolean isRight; Random random; int maxInteger;

JTextField textOne,textTwo,textResult; JLabel operatorLabel,message; Teacher(){ }

public void setMaxInteger(int n){ }

public void actionPerformed(ActionEvent e){

String str=e.getActionCommand(); if(str.equals(\

numberOne=random.nextInt(maxInteger)+1; numberTwo=random.nextInt(maxInteger)+1; double d=Math.random(); if(d>=0.5){ }

textOne.setText(\textTwo.setText(\operatorLabel.setText(operator); message.setText(\请回答\textResult.setText(null);

operator=\operator=\}else{ maxInteger=n; random=new Random();

}else if(str.equals(\

}

}

}

String answer=textResult.getText(); try{ }

int result=Integer.parseInt(answer); if(operator.equals(\ }

message.setText(\请输入数字字符\

if(result==numberOne+numberTwo){ }

if(result==numberOne-numberTwo){ }

message.setText(\你回答正确\message.setText(\你回答错误\}else{

message.setText(\你回答正确\message.setText(\你回答错误\}else{

}else if(operator.equals(\

}catch(NumberFormatException ex){

public void setJTextField(JTextField...t){ }

public void setJLabel(JLabel...label){ }

operatorLabel=label[0]; message=label[1]; textOne =t[0]; textTwo =t[1]; textResult =t[2];

ComputerFrame.java

import java.awt.*; import java.awt.event.*; import javax.swing.*;

public class ComputerFrame extends JFrame{

JMenuBar menubar; JMenu choiceGrade; JMenuItem grade1,grade2;

JTextField textOne,textTwo,textResult; JButton getProblem,giveAnswer; JLabel operatorLabel,message; Teacher teacherZhang;

ComputerFrame(){

teacherZhang=new Teacher(); teacherZhang.setMaxInteger(20); setLayout(new FlowLayout()); menubar=new JMenuBar();

choiceGrade=new JMenu(\选择级别\grade1=new JMenuItem(\幼儿级别\grade2=new JMenuItem(\儿童级别\

grade1.addActionListener(new ActionListener(){ });

grade2.addActionListener(new ActionListener(){ });

choiceGrade.add(grade1); choiceGrade.add(grade2); menubar.add(choiceGrade); setJMenuBar(menubar);

//【代码1】 //创建textOne,其可见字符长是5 textTwo=new JTextField(5); textResult=new JTextField(5); operatorLabel=new JLabel(\

operatorLabel.setFont(new Font(\message=new JLabel(\你还没有回答呢\getProblem=new JButton(\获取题目\giveAnswer=new JButton(\确认答案\

public void actionPerformed(ActionEvent e){ }

teacherZhang.setMaxInteger(50); public void actionPerformed(ActionEvent e){ }

teacherZhang.setMaxInteger(10);

add(getProblem); add(textOne); add(operatorLabel); add(textTwo); add(new Label(\ add(textResult); add(giveAnswer); add(message);

textResult.requestFocus(); textOne.setEditable(false); textTwo.setEditable(false);

getProblem.setActionCommand(\ textResult.setActionCommand(\ giveAnswer.setActionCommand(\

}

teacherZhang.setJTextField(textOne,textTwo,textResult); teacherZhang.setJLabel(operatorLabel,message);

//【代码2】//将teacherZhang注册为getProblem的ActionEvent事件监视器 //【代码3】//将teacherZhang注册为giveAnswer的ActionEvent事件监视器 //【代码4】//将teacherZhang注册为textResult的ActionEvent事件监视器 setVisible(true); validate();

setDefaultCloseOperation(DISPOSE_ON_CLOSE); }

MainClass.java

public class MainClass { }

public static void main(String[] args) { }

ComputerFrame frame; frame=new ComputerFrame(); frame.setTitle(\算术测试\frame.setBounds(100,100,650,180);

实验2 布局与日历

模板代码

CalendarBean.java

import java.util.Calendar; public class CalendarBean { String [] day;

int year=2008,month=0;

public int getYear() { }

public void setYear(int year) { }

public int getMonth() { }

public void setMonth(int month) {

this.month = month; }

return month; this.year = year; return year;

public String [] getCalendar() { String [] a=new String[42];

Calendar 日历=Calendar.getInstance(); 日历.set(year,month-1,1);

int 星期几=日历.get(Calendar.DAY_OF_WEEK)-1; int day=0;

if(month==1||month==3||month==5||month==7||month==8||month==10||month==12) day=31;

if(month==4||month==6||month==9||month==11) day=30; if(month==2) {

if(((year%4==0)&&(year0!=0))||(year@0==0)) day=29; else day=28; }

for(int i=星期几,n=1;i<星期几+day;i++) { a[i]=String.valueOf(n) ; n++; } return a; } }

CalendarFrame.java

import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import java.awt.*; import java.util.*;

public class CalendarFrame extends JFrame implements ActionListener {

JLabel labelDay[]=new JLabel[42]; JButton titleName[]=new JButton[7];

String name[]={\日\一\二\三\四\五\六\JButton nextMonth,previousMonth; CalendarBean calendar;

JLabel showMessage=new JLabel(\int year=2011,month=2; public CalendarFrame(){

JPanel pCenter=new JPanel();

//【代码1】//将pCenter的布局设置为7行7列的GridLayout布局. for(int i=0;i<7;i++){ }

titleName[i]=new JButton(name[i]);

titleName[i].setBorder(new SoftBevelBorder(BevelBorder.RAISED)); //【代码2】//pCenter中添加组件titleName[i]

}

for(int i=0;i<42;i++){ }

calendar=new CalendarBean(); nextMonth=new JButton(\下月\previousMonth=new JButton(\上月\nextMonth.addActionListener(this); previousMonth.addActionListener(this); JPanel pNoth=new JPanel()

,pSouth=new JPanel(); pNoth.add(previousMonth); pNoth.add(nextMonth); pSouth.add(showMessage);

//【代码4】//将窗口pCenter添加到中央区域 //【代码5】//将窗口pNoth添加到北面区域 //【代码6】//将窗口pSouth添加到南面区域 setYearAndMonth(year,month);

setDefaultCloseOperation(DISPOSE_ON_CLOSE);

labelDay[i]=new JLabel(\

labelDay[i].setBorder(new SoftBevelBorder(BevelBorder.LOWERED)); //【代码3】//pCenter中添加组件labelDay[i]

public void setYearAndMonth(int y,int m){ }

public void actionPerformed(ActionEvent e) {

if(e.getSource()==nextMonth){ }

else if(e.getSource()==previousMonth){

month=month-1; month=month+1; if(month>12){ }

calendar.setMonth(month); String day[]=calendar.getCalendar(); for(int i=0;i<42;i++){ }

labelDay[i].setText(day[i]); month=1;

calendar.setYear(y); calendar.setMonth(m);

String day[]= calendar.getCalendar(); for(int i=0;i<42;i++){ }

showMessage.setText(\日历:\年\月\

labelDay[i].setText(day[i]);

}

}

}

if(month<1){ }

calendar.setMonth(month); String day[]=calendar.getCalendar(); for(int i=0;i<42;i++){ }

labelDay[i].setText(day[i]); month=12;

showMessage.setText(\日历:\年\月\

CalendarMainClass.java

public class CalendarMainClass { }

public static void main(String[] args) { }

CalendarFrame frame=new CalendarFrame(); frame.setBounds(100,100,360,300); frame.setVisible(true);

frame.setYearAndMonth(2013,5);

实验3 华容道

模板代码

MainClassHRR.java

public class MainClassHRR { }

public static void main(String[] args) { }

{ Hua_Rong_Road HRR=new Hua_Rong_Road(); }

Person.java

import java.awt.event.*; import java.awt.*; import javax.swing.*;

public class Person extends JButton implements FocusListener {

int number;

Color c=new Color(255,245,170);

Font font=new Font(\宋体\Person(int number,String s)

}

{ }

super(s); setBackground(c); setFont(font); this.number=number; c=getBackground(); addFocusListener(this);

public void focusGained(FocusEvent e) { }

public void focusLost(FocusEvent e) { }

setBackground(c); setBackground(Color.red);

Hua_Rong_Road.java

import java.awt.event.*; import java.awt.*; import javax.swing.*;

public class Hua_Rong_Road extends JFrame implements MouseListener,

KeyListener, ActionListener { Person person[]=new Person[10]; JButton left,right,above,below; JButton restart=new JButton(\重新开始\public Hua_Rong_Road() { }

public void init() {

setLayout(null); add(restart);

restart.setBounds(100,320,120,25); restart.addActionListener(this);

String name[]={\曹操\关羽\张\刘\周\黄\兵\兵\兵\兵\for(int k=0;k

person[0].setBounds(104,54,100,100);

person[k]=new Person(k,name[k]); person[k].addMouseListener(this); person[k].addKeyListener(this); add(person[k]); init();

setBounds(100,100,320,360); setVisible(true);

setDefaultCloseOperation(DISPOSE_ON_CLOSE); validate();

}

person[1].setBounds(104,154,100,50); person[2].setBounds(54, 154,50,100); person[3].setBounds(204,154,50,100); person[4].setBounds(54, 54, 50,100); person[5].setBounds(204, 54, 50,100); person[6].setBounds(54,254,50,50); person[7].setBounds(204,254,50,50); person[8].setBounds(104,204,50,50); person[9].setBounds(154,204,50,50); person[9].requestFocus();

left=new JButton(); right=new JButton(); above=new JButton(); below=new JButton(); add(left); add(right); add(above); add(below); left.setBounds(49,49,5,260); right.setBounds(254,49,5,260); above.setBounds(49,49,210,5); below.setBounds(49,304,210,5); validate();

public void keyTyped(KeyEvent e){} public void keyReleased(KeyEvent e){} public void keyPressed(KeyEvent e) { }

public void mousePressed(MouseEvent e) {

Person man=(Person)e.getSource(); int x=-1,y=-1; x=e.getX(); y=e.getY();

int w=man.getBounds().width; int h=man.getBounds().height; Person man=(Person)e.getSource(); if(e.getKeyCode()==KeyEvent.VK_DOWN) { }

if(e.getKeyCode()==KeyEvent.VK_UP) { }

if(e.getKeyCode()==KeyEvent.VK_LEFT) { }

if(e.getKeyCode()==KeyEvent.VK_RIGHT) { }

go(man,right); go(man,left); go(man,above); go(man,below);

}

if(y>h/2) { } if(yw/2) { }

go(man,right); go(man,left); go(man,above); go(man,below);

public void mouseReleased(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mouseClicked(MouseEvent e) {} public void go(Person man,JButton direction) {

boolean move=true;

Rectangle manRect=man.getBounds(); int x=man.getBounds().x; int y=man.getBounds().y; if(direction==below)

y=y+50; y=y-50; x=x-50; x=x+50;

else if(direction==above) else if(direction==left) else if(direction==right) manRect.setLocation(x,y);

Rectangle directionRect=direction.getBounds(); for(int k=0;k<10;k++) { }

if(manRect.intersects(directionRect)) { }

if(move==true) { }

man.setLocation(x,y); move=false;

Rectangle personRect=person[k].getBounds();

if((manRect.intersects(personRect))&&(man.number!=k)) { }

move=false;

}

}

public void actionPerformed(ActionEvent e) { }

dispose();

new Hua_Rong_Road();

实验4 字体对话框

模板代码

FontFamilyNames.java

import java.awt.GraphicsEnvironment; public class FontFamilyNames { String allFontName[]; public String [] getFontName()

{ GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment(); allFontName=ge.getAvailableFontFamilyNames(); return allFontName; } }

FontDialog.java

import java.awt.event.*; import java.awt.*; import javax.swing.*;

public class FontDialog extends JDialog implements ItemListener,ActionListener{

FontFamilyNames fontFamilyNames; int fontSize=38; String fontName;

JComboBox fontSizeList,fontNameList; JLabel label; Font font; JButton yes,cancel; static int YES=1,NO=0; int state=-1;

FontDialog(Frame f){ super(f);

setTitle(\字体\

font=new Font(\宋体\

fontFamilyNames=new FontFamilyNames();

//【代码1】//当前对话框调用setModal(boolean b)设置为有模式 yes=new JButton(\ cancel=new JButton(\

yes.addActionListener(this); cancel.addActionListener(this);

label=new JLabel(\奥运\ fontSizeList=new JComboBox(); fontNameList=new JComboBox();

String name[]=fontFamilyNames.getFontName(); fontNameList.addItem(\字体\ for(int k=0;k

fontSizeList.addItem(\大小\ for(int k=8;k<72;k=k+2) { }

fontNameList.addItemListener(this); fontSizeList.addItemListener(this); JPanel pNorth=new JPanel(); pNorth.add(fontNameList); pNorth.add(fontSizeList);

add(pNorth,BorderLayout.NORTH); add(label,BorderLayout.CENTER); JPanel pSouth=new JPanel(); pSouth.add(yes); pSouth.add(cancel);

add(pSouth,BorderLayout.SOUTH); setBounds(100,100,280,170);

setDefaultCloseOperation(DISPOSE_ON_CLOSE); validate(); }

public void itemStateChanged(ItemEvent e) { }

label.setFont(font);

label.repaint(); validate();

fontName=(String)fontNameList.getSelectedItem(); font=new Font(fontName,Font.PLAIN,fontSize); Integer m=(Integer)fontSizeList.getSelectedItem(); fontSize=m.intValue();

font=new Font(fontName,Font.PLAIN,fontSize);

if(e.getSource()==fontNameList){

fontSizeList.addItem(new Integer(k)); fontNameList.addItem(name[k]);

}else if(e.getSource()==fontSizeList){

}

public void actionPerformed(ActionEvent e)

{

{ }

if(e.getSource()==yes) { }

state=NO;

//【代码3】//对话框设置为不可见

state=YES;

//【代码2】//对话框设置为不可见

else if(e.getSource()==cancel)

}

public int getState() {

return state;

}

public Font getFont()

return font;

{ } }

FrameHaveDialog.java

import java.awt.event.*; import java.awt.*; import javax.swing.*;

public class FrameHaveDialog extends JFrame implements ActionListener { JTextArea text; JButton buttonFont; FrameHaveDialog()

{ buttonFont=new JButton(\设置字体\ text=new JTextArea(\面向对象程序设计\ buttonFont.addActionListener(this); add(buttonFont,BorderLayout.NORTH); add(text);

setBounds(60,60,300,300); setVisible(true); validate();

setDefaultCloseOperation(DISPOSE_ON_CLOSE); }

public void actionPerformed(ActionEvent e) { if(e.getSource()==buttonFont)

{ FontDialog dialog=new FontDialog(this);//【代码4】//创建对话框 dialog.setVisible(true);//【代码5】//对话框设置为可见 //【代码6】 //对话框设置设置标题为“字体对话框” if(dialog.getState()==FontDialog.YES) { text.setFont(dialog.getFont()); text.repaint(); }

if(dialog.getState()==FontDialog.NO) { text.repaint(); } } } }

FontDialogMainClass.java

public class FontDialogMainClass { public static void main(String args[])

{ FrameHaveDialog win=new FrameHaveDialog(); } }

实验5 计算平方根

模板代码 InputNumber.java

import javax.swing.*; public class InputNumber {

public static void main(String[] args) { } }

double result=0;

boolean inputComplete=false; while(inputComplete==false){ }

double sqrtRoot=Math.sqrt(result);

System.out.println(result+\平方根:\

String str=//【代码1】//弹出输入对话框 try{ }

result=Double.parseDouble(str); if(result>=0){ }

//【代码2】//弹出消息对话框 inputComplete=false;

inputComplete=true;

}catch(NumberFormatException exp){

实验6 简易计算器

模板代码

UserFrm.java

import java.awt.*; import java.awt.event.*;

public class UserFrm extends Frame implements ActionListener { private MenuBar jmb = new MenuBar();

private MenuItem item = new MenuItem(\退 出\ public static Font font = new Font(\宋体\

public UserFrm(String title) throws HeadlessException { }

public void actionPerformed(ActionEvent e) { }

public static void main(String[] args) { } }

class Caculator extends Panel implements ActionListener, KeyListener { private TextField tf = new TextField(\ private float x = 0; private float y = 0; private int code = 0; private boolean enable;

new UserFrm(\用户界面\Object o = e.getSource(); if (o == item)

System.exit(1); super(title);

//【代码1】//设置该Frame位置与大小,具体值为(100, 100, 250, 200) setVisible(true);

Menu menu = new Menu(\文 件\menu.add(item); item.setFont(font);

Panel panelNorth = new Panel();

//【代码2】//把panelNorth加入窗体的北区 add(new Caculator(), BorderLayout.CENTER); item.addActionListener(this); jmb.add(menu); jmb.setFont(font); setMenuBar(jmb);

//【代码3】//用匿名类的方式设计完成窗体关闭的监听和实现关闭的方法 validate();

private boolean first; private String str = \

public Caculator() {

setLayout(new BorderLayout()); enable = true; first = true;

add(tf, BorderLayout.NORTH); Panel panel = new Panel();

//【代码4】//把panel设置为GridLayout布局 Button btn = null;

//【代码5】//创建btn并把标题设为1;把btn加入panel中;设置该按钮的字体格式为UserFrm.font;//【代码6】//创建btn并把标题设为2;把btn加入panel中;设置该按钮的字体格式为UserFrm.font;//【代码7】//创建btn并把标题设为3;把btn加入panel中;设置该按钮的字体格式为UserFrm.font;//【代码8】//创建btn并把标题设为+;把btn加入panel中;设置该按钮的字体格式为UserFrm.font;//【代码9】//创建btn并把标题设为4;把btn加入panel中;设置该按钮的字体格式为UserFrm.font;//【代码10】//创建btn并把标题设为5;把btn加入panel中;设置该按钮的字体格式为UserFrm.font;//【代码11】//创建btn并把标题设为6;把btn加入panel中;设置该按钮的字体格式为UserFrm.font;//【代码12】//创建btn并把标题设为-;把btn加入panel中;设置该按钮的字体格式为UserFrm.font;//【代码13】//创建btn并把标题设为7;把btn加入panel中;设置该按钮的字体格式为UserFrm.font;//【代码14】//创建btn并把标题设为8;把btn加入panel中;设置该按钮的字体格式为UserFrm.font;///【代码15】//创建btn并把标题设为9;把btn加入panel中;设置该按钮的字体格式为UserFrm.font;//【代码16】//创建btn并把标题设为*;把btn加入panel中;设置该按钮的字体格式为UserFrm.font;//【代码17】//创建btn并把标题设为0;把btn加入panel中;设置该按钮的字体格式为UserFrm.font;//【代码18】//创建btn并把标题设为.;把btn加入panel中;设置该按钮的字体格式为UserFrm.font;//【代码19】//创建btn并把标题设为/;把btn加入panel中;设置该按钮的字体格式为UserFrm.font;btn = new Button(\panel.add(btn);

btn.setFont(UserFrm.font);

设置输入确认监听;设置键盘输入监听 设置输入确认监听;设置键盘输入监听 设置输入确认监听;设置键盘输入监听 设置输入确认监听;设置键盘输入监听 设置输入确认监听;设置键盘输入监听 设置输入确认监听;设置键盘输入监听 设置输入确认监听;设置键盘输入监听 设置输入确认监听;设置键盘输入监听 设置输入确认监听;设置键盘输入监听 设置输入确认监听;设置键盘输入监听 设置输入确认监听;设置键盘输入监听 设置输入确认监听;设置键盘输入监听 设置输入确认监听;设置键盘输入监听 设置输入确认监听;设置键盘输入监听 设置输入确认监听;设置键盘输入监听

}

btn.addActionListener(this); btn.addKeyListener(this);

//【代码20】//把panel加入Caculator的中部区域中

public void actionPerformed(ActionEvent e) {

}

if (e.getActionCommand() == \

else { }

tf.setText(e.getActionCommand()); enable = true;

if (e.getActionCommand() == \ }

if (e.getActionCommand() == \ }

if (e.getActionCommand() == \ }

if (e.getActionCommand() == \ }

if (e.getActionCommand() != \

}

&& e.getActionCommand() != \&& e.getActionCommand() != \if (first) { }

tf.setText(e.getActionCommand()); first = false;

tf.setText(tf.getText() + e.getActionCommand());

x = Float.parseFloat(tf.getText()); code = 3; this.tf.setText(\

//【代码21】//把文本框里的数字转成浮点型,赋给x code = 2; this.tf.setText(\

//【代码21】//把文本框里的数字转成浮点型,赋给x code = 1; this.tf.setText(\

//【代码21】//把文本框里的数字转成浮点型,赋给x code = 0; this.tf.setText(\

if (enable) {

} else {

}

}

switch (code) { case 0: }

//【代码22】//完成两个数的加法运算 tf.setText(Float.toString(y)); enable = false; break;

//【代码23】//完成两个数的减法运算 tf.setText(Float.toString(y)); enable = false; break;

//【代码24】//完成两个数的乘法运算 tf.setText(Float.toString(y)); enable = false; break;

//【代码25】//完成两个数的除法运算 tf.setText(Float.toString(y)); enable = false; break;

case 1:

case 2:

case 3:

public void keyPressed(KeyEvent e) {

if (e.getKeyChar() == '+') { }

if (e.getKeyChar() == '-') { }

if (e.getKeyChar() == '*') { }

if (e.getKeyChar() == '/') {

x = Float.parseFloat(tf.getText()); code = 3;

x = Float.parseFloat(tf.getText()); code = 2; this.tf.setText(\

x = Float.parseFloat(tf.getText()); code = 1; this.tf.setText(\

x = Float.parseFloat(tf.getText()); code = 0; this.tf.setText(\

}

}

this.tf.setText(\

if (【代码26】) {//判断用键盘输入的数字是否为0-9以及.号,其中的一个。 }

if (【代码28】) {//判断用键盘输入的地键是否是回车确认键。 }

switch (code) { case 0: }

y = x + Float.parseFloat(this.tf.getText());//完成两个数的加法运算 tf.setText(Float.toString(y)); enable = false; break;

y = x - Float.parseFloat(this.tf.getText());//完成两个数的减法运算 tf.setText(Float.toString(y)); enable = false; break;

y = x * Float.parseFloat(this.tf.getText());//完成两个数的乘法运算 tf.setText(Float.toString(y)); enable = false; break;

y = x / Float.parseFloat(this.tf.getText());//完成两个数的除法运算 tf.setText(Float.toString(y)); enable = false; break; if (enable) { }

//【代码27】//在文本框中输入一个数字并显示。当再次输入数字时,把原数据放大

//提示:用first确定数字是否第一次输入数据;用字符串合并来放大十倍。

十倍再并上第二次输入的数据。

} else {

str = Character.toString(e.getKeyChar()); tf.setText(str); enable = true;

case 1:

case 2:

case 3:

public void keyReleased(KeyEvent arg0) { }

public void keyTyped(KeyEvent arg0) { }

}

本文来源:https://www.bwwdw.com/article/0yer.html

Top