會寫程式的貓
2009年5月15日
網路程式設計 2009/05/16 作業
User:
MY BLOG
Class:
Java
,
Java - 網路程式設計 作業
/* 攝氏 轉 華氏 */ import java.awt.*; import java.awt.event.*; class JavaCtoF implements TextListener{ Frame frm=new Frame("JavaCtoF"); TextField c=new TextField(6); TextField f=new TextField(6); TextArea txa1=new TextArea("",6,10,TextArea.SCROLLBARS_NONE); Button btn=new Button("加入"); public JavaCtoF(){ frm.setLayout(new FlowLayout(FlowLayout.CENTER)); c.addTextListener(this); frm.add(c); frm.add(f); frm.setSize(200,200); frm.setVisible(true); } public void textValueChanged(TextEvent e){ double x = 0; if(!c.getText().equals("")) x = (Double.parseDouble(c.getText()) * 9 / 5) + 32 ; f.setText(Double.toString(x)); } public static void main(String args[]){ new JavaCtoF(); } }
/*統一發票兌獎*/ import java.awt.*; import java.awt.event.*; class JavaBingo implements TextListener{ Frame frm=new Frame("JavaBingo"); TextField n1=new TextField(6); TextField n2=new TextField(6); TextField n3=new TextField(6); TextField n4=new TextField(6); TextField n=new TextField(6); Label lab1 = new Label("特獎號碼"); Label lab2 = new Label("頭獎號碼"); Label lab3 = new Label("發票號碼"); Label ans = new Label(); Panel p1 = new Panel(new GridLayout(1,2,2,2)); Panel p2 = new Panel(new GridLayout(1,2,2,2)); Panel p3 = new Panel(new GridLayout(1,2,2,2)); BorderLayout border = new BorderLayout();//版面配置 //Button btn=new Button("加入"); public JavaBingo(){ frm.setLayout(null); n.addTextListener(this); p1.add(lab1); p1.add(n1); p2.add(lab2); p2.add(n2); p2.add(n3); p2.add(n4); p3.add(lab3); p3.add(n); p3.add(ans); p1.setBounds(20,50,150,20); p2.setBounds(20,80,300,20); p3.setBounds(20,120,225,20); frm.add(p1,border.CENTER); frm.add(p2,border.CENTER); frm.add(p3,border.CENTER); frm.setSize(400,200); frm.setVisible(true); } public void textValueChanged(TextEvent e){ int m = 0; int i[] = new int[3]; i[0] = 0; i[1] = 0; i[2] = 0; if(n.getText().length() == n2.getText().length()) for( int x = n2.getText().length()-1 ; x >= 0 ; x-- ){ if( n.getText().charAt(x) != n2.getText().charAt(x)){ break; } i[0]++; } if((n.getText().length() == n3.getText().length())) for( int x = n3.getText().length()-1 ; x >= 0 ; x-- ){ if( n.getText().charAt(x) != n3.getText().charAt(x)){ break; } i[1]++; } if((n.getText().length() == n4.getText().length())) for( int x = n4.getText().length()-1 ; x >= 0 ; x-- ){ if( n.getText().charAt(x) != n4.getText().charAt(x)){ break; } i[2]++; } for( int x = 0 ; x < i.length ; x++ ){ if( i[x] > m ) m = i[x]; } if(9-m <= 6) ans.setText(Integer.toString(9-m)+" 獎"); else ans.setText("無"); if((n.getText().length() == n1.getText().length())) if(n.getText().equals(n1.getText())) ans.setText("特獎"); } public static void main(String args[]){ new JavaBingo(); } }
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言