May 30, 2009

我的JAVA GUI程式

我先從畢氏定理開始寫(先挑簡單的..)

其中還是有錯誤...

像LABEL的問題OTZ

用爛方法解決..(默)



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

public class test3
{
private static Frame frm=new Frame("畢氏定理");
private static Panel pn1=new Panel(new GridLayout());
private static List lst = new List() ;
private static Button btn1 =new Button("開始") ;
private static Button btn2 =new Button("結束") ;
private static Label lal2 =new Label();
private static Label lal4 =new Label();
private static Label lal5 =new Label();
private static int N , M ;
public static void main(String[] args) {

frm.add(btn1) ;
btn1.addActionListener(new ActLis());
frm.add(btn2) ;
btn2.addActionListener(new ActLis());

Label lal =new Label("運算次數: ") ;
Label lal3 =new Label("幾組解: ") ;

pn1.add(lst);
frm.add(pn1);
frm.add(lal);
frm.add(lal3);
frm.add(lal2);
frm.add(lal4);
frm.add(lal5);



frm.addWindowListener(new WindowAdapter(){public void
windowClosing(WindowEvent e){System.exit(0);}});

frm.setBounds(450,250,450,300);
pn1.setBounds(30,60,300,200);
btn1.setBounds(360,100,60,30);
btn2.setBounds(360,200,60,30);
lal.setBounds(30,250,55,50);
lal3.setBounds(200,250,55,50);
lal2.setBounds(85,250,55,50);
lal4.setBounds(255,250,55,50);
frm.setVisible(true);
}

public static class ActLis implements ActionListener

{

public void actionPerformed(ActionEvent e){
Button btn=(Button) e.getSource();
if (btn==btn1){
output_btn1(btn1);
}
else{
output_btn2(btn2);}
}

private void output_btn1(Button btn1){
N=0 ;
M=0 ;
for(int C=5;C <=100;C++){
for(int B=4;B<=(C-1);B++){
for(int A=3;A<=(B-1);A++){
N = N + 1 ;
if(C<(B+A)& (C*C)==(A*A+B*B)){
lst.add(A + " " +B + " " + C + " ");
M = M + 1 ;
}
}
}
}
pn1.add(lst) ;
lal2.setText(Long.toString(N));
lal4.setText(Long.toString(M));
}
private void output_btn2(Button btn2){
System.exit(0);
}
}
}
Photobucket Photobucket

0推薦此文章
Today's Visitors: 0 Total Visitors: 35
Personal Category: Uncategorized Articles Topic: creation / design / industrial design
[Trackback URL]

Post A Comment









Yes No



Please input the magic number:

( Prevent the annoy garbage messages )
( What if you cannot see the numbers? )
Please input the magic number

誰來收藏
Loading ...
unlog_NVPO 0