Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java GUI 设计  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 我刚学JAVA,请前辈帮我完善下下面程序。
358182552





发贴: 8
积分: 0
于 2006-03-19 11:46 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
(?)
我想GUI输出1到100的质数个数并且将质数也输出
目前这个不完整的程序只能输出质数个数和最后一个质数
麻烦您们帮我完善下,谢谢!!!!!!

import javax.swing.*;//控件面版
import java.awt.event.ActionListener;//活动监听
import java.awt.event.ActionEvent;//事件响应

public class TB extends JFrame //定义框架
{
private JPanel jPanel1;
private JTextField jT1;
private JTextField jT2;//文本框
private JButton jb1=new JButton("按钮");//按钮
private JButton jb2=new JButton("退出");
public TB()
{
  super("求从1到100之间的素数个数");
  setSize(500,350);
  jPanel1=new JPanel();
  jPanel1.add(jb1);
  jPanel1.add(jb2);//添加按钮
  jT1=new JTextField(4);
  jT2=new JTextField(30);
  jPanel1.add(jT1);
  jPanel1.add(jT2);
  jb1.addActionListener(new ActionListener() //对jb1添加监听动作
  {
    public void actionPerformed(ActionEvent e)//响应事件程序
  {int n=0,m,j,i,count=0;
    for(i=2;i<=100;i++)
    {m=(int)Math.sqrt((double)i);
    for(j=2;j<=m;j++)
    if((i%j)==0 ) break;
    if(j>=m+1)
    {if(n%5==0)System.out.println("\n");
    System.out.print(i+" ");
     n++;
     count++;
     String st=String.valueOfLight Bulb;
     String str=String.valueOf(count);
     jT1.setText(str);
     jT2.setText(st);
    
    }
    }
    
  }
  });
  jb2.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ex){
      System.out.println("程序结束...");
      System.exit(0);
    }
  });

  this.setContentPane(jPanel1);
  }

public static void main(String aa[]){
TB ta=new TB();
  ta.show();
}
}



作者 Re:我刚学JAVA,请前辈帮我完善下下面程序。 [Re:358182552]
jackyangf





发贴: 58
积分: 1
于 2006-03-20 14:02 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
jT1.setText(str);
jT2.setText(st);

在for循环里,这样的话肯定显示的是最后一次的值了
如果 i 是质数,保存起来,最后在输出
String allPrimeNums = "";
int count = 0;
for( 0-100) {
....
if( i 是 质数) {
allPrimeNums += String.valueOf ( i );
allPrimeNums += " ";//加个空格 逗号什么的分隔符
count++;
}
}// 循环结束
setText(.....)



作者 Re:我刚学JAVA,请前辈帮我完善下下面程序。 [Re:358182552]
jianandjian





发贴: 3
积分: 0
于 2006-03-24 11:12 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我觉得你这种算法院时间效应不是很好


作者 Re:我刚学JAVA,请前辈帮我完善下下面程序。 [Re:358182552]
jianandjian





发贴: 3
积分: 0
于 2006-03-24 11:13 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我觉得你这种算法院时间效应不是很好


作者 Re:我刚学JAVA,请前辈帮我完善下下面程序。 [Re:358182552]
358182552





发贴: 8
积分: 0
于 2006-04-02 13:31 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
谢谢了啊!!



flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923