算法想出来了,接口类JLabel和JTextArea不会添加! 看看swing的例子吧,这个不难的,动手先练练:) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 为了分,我写:import java.io.*;import javax.swing.*;import java.awt.*;import java.awt.event.*;public class TestZhiyinzi extends JFrame { JPanel contentPane=(JPanel)this.getContentPane(); JPanel jpanel1=new JPanel(new FlowLayout(FlowLayout.LEADING)); JPanel jpanel2=new JPanel(new FlowLayout(FlowLayout.LEADING)); JTextField input=new JTextField("Please input a quality number",20); JButton jbutton=new JButton("GO"); JLabel jl=new JLabel("Not quality number:"); JTextArea jta=new JTextArea("Quality number",3,20); public TestZhiyinzi() { this.setBounds(200,200,400,300); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); contentPane.add(jpanel1,BorderLayout.NORTH); jpanel1.add(input); jpanel1.add(jbutton); jpanel2.add(jl); jpanel2.add(jta); jbutton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { click_jbutton(e); } }); contentPane.add(jpanel2,BorderLayout.CENTER); this.setVisible(true); } public void click_jbutton(ActionEvent e) { String s; s=input.getText(); int iNum=0; try{ iNum=Integer.parseInt(s); }catch(Exception ex){ JOptionPane.showMessageDialog(this,"Please input a Number!"); return; } if(iNum==1) { JOptionPane.showMessageDialog(this,"Your input is Number 1!"); return; } getZhiyinzi(iNum); } public static void main(String args[])throws Exception { new TestZhiyinzi(); } void getZhiyinzi(int iNum) { String s=""; for (int i = 2; i<=iNum; i++) { if (iNum%i==0) { if (isPrime(i)) { if(i<iNum) { s+=i+" is a quality factor \r\n"; jta.setText(""); } if(i==iNum) { jl.setText("Quality number"); jta.setText("Your Input is a Quality Number!"); return; } } } } jl.setText(s); } static boolean isPrime(int i) { for (int j=2; j<i; j++) { if (i%j==0) { return false; } } return true; }} //看看吧,早知道浪费了那么多时间就用口说算了import java.io.*;import javax.swing.*;import java.awt.*;import java.awt.event.*;public class TestZhiyinzi extends JFrame{ JTextArea primeArea=new JTextArea(100,200); JLabel yinzi=new JLabel("erewr"); public static void main(String args[])throws Exception { TestZhiyinzi frame=new TestZhiyinzi(); } public TestZhiyinzi() { this.getContentPane().setLayout(new BorderLayout()); this.getContentPane().add(yinzi,BorderLayout.SOUTH); this.getContentPane().add(primeArea,BorderLayout.CENTER); this.setSize(300,400); this.show(); this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e){ System.exit(0); } }); String s=""; BufferedReader br=new BufferedReader( new InputStreamReader(System.in)); while(true) { try{ System.out.println("请您随便输入一个自然数:"); s=br.readLine();} catch(IOException e){} int iNum=Integer.parseInt(s); if(iNum==1) { System.out.println("没事儿干了!"); } getZhiyinzi(iNum); } } void getZhiyinzi(int iNum) { String str=""; for (int i = 2; i<=iNum; i++) { primeArea.setText(""); if (iNum%i==0) { if (isPrime(i)) { if(i<iNum) { str=str+i+" "; } if(i==iNum) primeArea.setText("您上面所输入的数"+i+"是素数"); else yinzi.setText(str+"是这个非素数的质因子"); } } } } static boolean isPrime(int i) { for (int j=2; j<i; j++) { if (i%j==0) { return false; } } return true; } } 句柄的作用是什么 很奇怪的异常,大家帮看下 java数据库连接问题 一个图形设计方面的问题 一个不明白的错误,解决立刻给分!请进! 心中一直以来的疑问 谁告诉我答案,我立马把100分都给他。骗人是小狗 JAVA的好书 新手请教:我想在HTML中插入个applet,可不知applet中的程序源code、程序URLcodebase、参数名param name、参数值param value该填什么,能举例说明吗?万分感激 Java编程中怎样才能生成包括全部汉字的字符串 关于sax对xml读写操作!!!!!!!! 关于Graphics类与Graphics2D类的用法,一点小问题
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;public class TestZhiyinzi extends JFrame {
JPanel contentPane=(JPanel)this.getContentPane();
JPanel jpanel1=new JPanel(new FlowLayout(FlowLayout.LEADING));
JPanel jpanel2=new JPanel(new FlowLayout(FlowLayout.LEADING));
JTextField input=new JTextField("Please input a quality number",20);
JButton jbutton=new JButton("GO");
JLabel jl=new JLabel("Not quality number:");
JTextArea jta=new JTextArea("Quality number",3,20);
public TestZhiyinzi() {
this.setBounds(200,200,400,300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
contentPane.add(jpanel1,BorderLayout.NORTH);
jpanel1.add(input);
jpanel1.add(jbutton);
jpanel2.add(jl);
jpanel2.add(jta);
jbutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
click_jbutton(e);
}
});
contentPane.add(jpanel2,BorderLayout.CENTER);
this.setVisible(true);
} public void click_jbutton(ActionEvent e) {
String s;
s=input.getText();
int iNum=0;
try{
iNum=Integer.parseInt(s);
}catch(Exception ex){
JOptionPane.showMessageDialog(this,"Please input a Number!");
return;
}
if(iNum==1) {
JOptionPane.showMessageDialog(this,"Your input is Number 1!");
return;
}
getZhiyinzi(iNum);
} public static void main(String args[])throws Exception
{
new TestZhiyinzi();
} void getZhiyinzi(int iNum)
{
String s="";
for (int i = 2; i<=iNum; i++) {
if (iNum%i==0)
{
if (isPrime(i))
{
if(i<iNum) {
s+=i+" is a quality factor \r\n";
jta.setText("");
}
if(i==iNum) {
jl.setText("Quality number");
jta.setText("Your Input is a Quality Number!");
return;
}
}
}
}
jl.setText(s);
}
static boolean isPrime(int i)
{
for (int j=2; j<i; j++)
{
if (i%j==0)
{
return false;
}
}
return true; }
}
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TestZhiyinzi extends JFrame
{
JTextArea primeArea=new JTextArea(100,200);
JLabel yinzi=new JLabel("erewr");
public static void main(String args[])throws Exception
{
TestZhiyinzi frame=new TestZhiyinzi();
}
public TestZhiyinzi()
{
this.getContentPane().setLayout(new BorderLayout()); this.getContentPane().add(yinzi,BorderLayout.SOUTH);
this.getContentPane().add(primeArea,BorderLayout.CENTER);
this.setSize(300,400);
this.show();
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
String s="";
BufferedReader br=new BufferedReader(
new InputStreamReader(System.in));
while(true)
{
try{
System.out.println("请您随便输入一个自然数:");
s=br.readLine();}
catch(IOException e){}
int iNum=Integer.parseInt(s);
if(iNum==1)
{
System.out.println("没事儿干了!");
}
getZhiyinzi(iNum);
}
}
void getZhiyinzi(int iNum)
{
String str="";
for (int i = 2; i<=iNum; i++)
{
primeArea.setText("");
if (iNum%i==0)
{
if (isPrime(i))
{
if(i<iNum)
{
str=str+i+" ";
}
if(i==iNum)
primeArea.setText("您上面所输入的数"+i+"是素数");
else
yinzi.setText(str+"是这个非素数的质因子");
}
}
}
}
static boolean isPrime(int i)
{
for (int j=2; j<i; j++)
{
if (i%j==0)
{
return false;
}
}
return true;
}
}