求JAVA程序代码
做一个手机界面要求:使用swing组件可以输入电话号码并显示按'yes'显示正在连接******号码5miao后显示正在通话中按’NO‘取消屏幕上的显示无显示时显示“关机...
做一个手机界面
要求:使用swing组件
可以输入电话号码 并显示
按'yes'显示正在连接******号码
5miao后显示 正在通话中
按’NO‘取消 屏幕上的显示 无显示时显示“关机” 2秒后关闭窗口
按“C”键删除上一个输入的数字 展开
要求:使用swing组件
可以输入电话号码 并显示
按'yes'显示正在连接******号码
5miao后显示 正在通话中
按’NO‘取消 屏幕上的显示 无显示时显示“关机” 2秒后关闭窗口
按“C”键删除上一个输入的数字 展开
1个回答
展开全部
import java.awt.Button;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.JFrame;
public class MyMobilePhone extends JFrame{
TextArea ta = new TextArea(10,21);
Button[] jb = new Button[12];
Button jbAnswer = new Button("YES");
Button jbRefuse = new Button("NO");
Button jbCancel = new Button("C");
MyMobilePhone(){
jb[10] = new Button("*");
jb[11] = new Button("#");
for(int i =0;i<10;i++){
String label =i+"";
System.out.println(label);
jb[i]=new Button(label);
jb[i].addActionListener(new MyButton());
}
jb[10].addActionListener(new MyButton());
jb[11].addActionListener(new MyButton());
jbCancel.addActionListener(new Cancel());
jbAnswer.addActionListener(new Answer());
jbRefuse.addActionListener(new Refuse());
setSize(200,400);
setLayout(new GridLayout(2,1));
Panel pup = new Panel();
pup.add(ta);
Panel pdown = new Panel(new GridLayout(2,1));
Panel p1 = new Panel(new GridLayout(1,3));
p1.add(jbCancel);
p1.add(jbAnswer);
p1.add(jbRefuse);
pdown.add(p1);
Panel p2 = new Panel(new GridLayout(4,3));
for(int i=1;i<10;i++){
p2.add(jb[i]);
}
p2.add(jb[10]);
p2.add(jb[0]);
p2.add(jb[11]);
pdown.add(p2);
add(pup);
add(pdown);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private class MyButton implements ActionListener{
public void actionPerformed(ActionEvent e) {
Button but = (Button)e.getSource();
String exp = ta.getText();
exp = exp+ but.getLabel();
ta.setText(exp);
int k=5;
while(k==0)k=k+1;
}
}
private class Refuse implements ActionListener{
public void actionPerformed(ActionEvent e){
String str = ta.getText();
if(str.equals("")){
new ShutDown(str).start();
}else{
ta.setText("");
}
}
}
private class Answer implements ActionListener{
public void actionPerformed(ActionEvent e){
String str = ta.getText();
if(!str.equals("")){
new CallOut(str).start();
}
}
}
class ShutDown extends Thread{
String str=null;
ShutDown(String str){
this.str=str;
}
int i = 0;
public void run(){
while(true){
i++;
GregorianCalendar gc = new GregorianCalendar();
String time = gc.get(Calendar.HOUR)+":"+gc.get(Calendar.MINUTE)+":"+gc.get(Calendar.SECOND);
try{
sleep(1000);
}catch(InterruptedException e){
System.out.println(e);
}
if(i == 2){
dispose();
}
}
}
}
class CallOut extends Thread{
String str=null;
CallOut(String str){
this.str=str;
}
int i = 0;
public void run(){
while(true){
i++;
GregorianCalendar gc = new GregorianCalendar();
String time = gc.get(Calendar.HOUR)+":"+gc.get(Calendar.MINUTE)+":"+gc.get(Calendar.SECOND);
try{
sleep(1000);
}catch(InterruptedException e){
System.out.println(e);
}
if(i == 5){
ta.setText("正在连接"+str+"号码");
}
}
}
}
private class Cancel implements ActionListener{
public void actionPerformed(ActionEvent e) {
String str = ta.getText();
if(!str.equals("")){
ta.setText(str.substring(0,str.length()-1));
}
}
}
public static void main(String[] args) {
new MyMobilePhone();
}
}
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.JFrame;
public class MyMobilePhone extends JFrame{
TextArea ta = new TextArea(10,21);
Button[] jb = new Button[12];
Button jbAnswer = new Button("YES");
Button jbRefuse = new Button("NO");
Button jbCancel = new Button("C");
MyMobilePhone(){
jb[10] = new Button("*");
jb[11] = new Button("#");
for(int i =0;i<10;i++){
String label =i+"";
System.out.println(label);
jb[i]=new Button(label);
jb[i].addActionListener(new MyButton());
}
jb[10].addActionListener(new MyButton());
jb[11].addActionListener(new MyButton());
jbCancel.addActionListener(new Cancel());
jbAnswer.addActionListener(new Answer());
jbRefuse.addActionListener(new Refuse());
setSize(200,400);
setLayout(new GridLayout(2,1));
Panel pup = new Panel();
pup.add(ta);
Panel pdown = new Panel(new GridLayout(2,1));
Panel p1 = new Panel(new GridLayout(1,3));
p1.add(jbCancel);
p1.add(jbAnswer);
p1.add(jbRefuse);
pdown.add(p1);
Panel p2 = new Panel(new GridLayout(4,3));
for(int i=1;i<10;i++){
p2.add(jb[i]);
}
p2.add(jb[10]);
p2.add(jb[0]);
p2.add(jb[11]);
pdown.add(p2);
add(pup);
add(pdown);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private class MyButton implements ActionListener{
public void actionPerformed(ActionEvent e) {
Button but = (Button)e.getSource();
String exp = ta.getText();
exp = exp+ but.getLabel();
ta.setText(exp);
int k=5;
while(k==0)k=k+1;
}
}
private class Refuse implements ActionListener{
public void actionPerformed(ActionEvent e){
String str = ta.getText();
if(str.equals("")){
new ShutDown(str).start();
}else{
ta.setText("");
}
}
}
private class Answer implements ActionListener{
public void actionPerformed(ActionEvent e){
String str = ta.getText();
if(!str.equals("")){
new CallOut(str).start();
}
}
}
class ShutDown extends Thread{
String str=null;
ShutDown(String str){
this.str=str;
}
int i = 0;
public void run(){
while(true){
i++;
GregorianCalendar gc = new GregorianCalendar();
String time = gc.get(Calendar.HOUR)+":"+gc.get(Calendar.MINUTE)+":"+gc.get(Calendar.SECOND);
try{
sleep(1000);
}catch(InterruptedException e){
System.out.println(e);
}
if(i == 2){
dispose();
}
}
}
}
class CallOut extends Thread{
String str=null;
CallOut(String str){
this.str=str;
}
int i = 0;
public void run(){
while(true){
i++;
GregorianCalendar gc = new GregorianCalendar();
String time = gc.get(Calendar.HOUR)+":"+gc.get(Calendar.MINUTE)+":"+gc.get(Calendar.SECOND);
try{
sleep(1000);
}catch(InterruptedException e){
System.out.println(e);
}
if(i == 5){
ta.setText("正在连接"+str+"号码");
}
}
}
}
private class Cancel implements ActionListener{
public void actionPerformed(ActionEvent e) {
String str = ta.getText();
if(!str.equals("")){
ta.setText(str.substring(0,str.length()-1));
}
}
}
public static void main(String[] args) {
new MyMobilePhone();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |