| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 535 人关注过本帖
标题:约瑟夫环的程序嵌进界面问题 急!求指导
只看楼主 加入收藏
holyhsw
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2011-6-12
结帖率:40%
收藏
已结贴  问题点数:10 回复次数:4 
约瑟夫环的程序嵌进界面问题 急!求指导
这是一个约瑟夫环的问题,程序和 界面都已经做出来了 但是不知道怎么合起来 求指导:
这是 约瑟夫环的程序:public person(int password, int number) {
    this.password = password;
    this.number = number;
   }
   public person(int number){
    this.number = number;
   }
  }

  public int ListLength(List<person> list) {
   int count = 0;
   if (list != null) {
    for (person p : list) {
     if (p.state != 0) {
      count++;
     }
    }
   }
   return count;
  }

  public void cacle() {
   // 初始化数据
   List<person> list = new LinkedList<person>();
   Scanner in = new Scanner(System.in);
   System.out.print("请输入人数n:");
    int n = in.nextInt();
    for(int i=0;i<n;i++){
        int a, b;
        a = in.nextInt();
        b = in.nextInt();
        list.add(new person(a,b));
    }
   
  // list.add(new person(4,7));

   int position = -1;//初始位置
   System.out.print("请输入第一次报多少的人出来m:");
   int m = in.nextInt(); //第一次报多少的人出来
   int count = 0;//已经报了多少人
   while (ListLength(list) != 0) {
   
    position = (position + 1) % list.size();// 位置定位

    if (((person) list.get(position)).state != 0) {
     count++;
    }
    if (count == m) {
     person p = list.get(position);
     System.out.print(p.number+" ");
     p.state = 0;
     m = p.password;
     list.set(position, p);
     count = 0;
    }
   }


  }
  public static void main(String[] args) {
   Question2 q= new Question2();
   q.cacle();
  }

 }


这是界面:
import java.awt.*;
import java.awt.event.*;
public class Question2Frame extends Frame implements ActionListener
{
private TextField text_1,text_2,text_3,text_4;
private Button button_1;
public Question2Frame()
    {
       super("约瑟夫环编辑器");
       this.setBounds(280,240,300,300);
       this.setBackground(java.awt.Color.cyan);
       this.setLayout(new java.awt.FlowLayout(FlowLayout.LEFT));
       this.add(new Label("人数n:"));
           text_1=new TextField("7",40);
       this.add(text_1);

       this.add(new Label("请输入每个人的密码,并用空格隔开:"));
       text_2=new TextField(40);
       this.add(text_2);

       this.add(new Label("第一个密码m:"));
       text_3=new TextField("20",40);
       this.add(text_3);

       this.add(new Label("输出结果为:"));
       text_4=new TextField(40);
       this.add(text_4);

       button_1=new Button("OK");
       this.add(button_1);

       this.addWindowListener(new WinClose());
       this.setVisible(true);
    }
    public void actionPerformed(ActionEvent e)
    {
    }
public static void main(String arg[])
    {
    new Question2Frame();
    }
}
class WinClose implements WindowListener
{
    public void windowClosing(WindowEvent e)
    {
        System.exit(0);
    }
    public void windowOpened(WindowEvent e){ }
    public void windowActivated(WindowEvent e){ }
    public void windowDeactivated(WindowEvent e){ }
    public void windowClosed(WindowEvent e){ }
    public void windowIconified(WindowEvent e){ }
    public void windowDeiconified(WindowEvent e){ }
}

求结合 !!
搜索更多相关主题的帖子: person password 约瑟夫 return null 
2011-06-12 13:17
付政委
该用户已被删除
收藏
得分:7 
提示: 作者被禁止或删除 内容自动屏蔽
2011-06-13 11:55
holyhsw
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2011-6-12
收藏
得分:0 
回复 2楼 付政委
不会 求全部的程序
2011-06-13 22:36
holyhsw
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2011-6-12
收藏
得分:0 
回复 2楼 付政委
不会 求全部的程序
2011-06-13 22:36
付政委
该用户已被删除
收藏
得分:0 
提示: 作者被禁止或删除 内容自动屏蔽
2011-06-14 17:19
快速回复:约瑟夫环的程序嵌进界面问题 急!求指导
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020350 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved