写随机抽号
无法显示结果,for语句无法执行
package Main;
//RandomNumber.java
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
public class Main extends JFrame{
private static final long serialVersionUID = 1L;
static JLabel MAX;
static JLabel MIN;
static JLabel NUMBER;
static JLabel GAP;
static JLabel result;
static JTextField max;
static JTextField min;
static JTextField number;
static JTextField gap;
static JButton Count;
static JTextArea Result;
static Panel Left,Right,MainPanel;
public static void main(String args[]) throws IOException{
int x = 500;
int y = 350;
JFrame F = new JFrame("RandomNumber");
//INIT
MAX =new JLabel("最大值:");
max = new JTextField("100",6);
MIN =new JLabel("最小值:");
min = new JTextField("10",6);
NUMBER = new JLabel("个数:");
number = new JTextField("1",6);
GAP = new JLabel("最小间隔:");
gap = new JTextField("10",6);
Count = new JButton("抽号");
result = new JLabel("结果:");
Result = new JTextArea(15,10);
Left = new Panel();
Right = new Panel();
Left.setLayout(new GridLayout(6,2,10,10));
Right.setLayout(new FlowLayout(FlowLayout.RIGHT));
F.setLayout(new FlowLayout(FlowLayout.LEFT));
//ADD-FIRST(LEFT)
Left.add(MAX);
Left.add(max);
Left.add(MIN);
Left.add(min);
Left.add(NUMBER);
Left.add(number);
Left.add(GAP);
Left.add(gap);
Left.add(Count);
Count.addActionListener(new Listener());
//ADD-FIRST(RIGHT)
Result.setEditable(false);
Right.add(result);
Right.add(Result);
//ADD-SECOND
MainPanel = new Panel();
MainPanel.add(Left);
MainPanel.add(Right);
F.add(MainPanel);
//END
F.setSize(x, y);
//SetLocation
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
int screenw = screenSize.width;
int screenh = screenSize.height;
F.setLocation((screenw-x)/2, (screenh-y)/2);
//SetVisible
F.setVisible(true);
F.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static String RandomInteger(int MaximumValue,int MinimumValue,int Range,int MinimumInterval) {
int TMP = 0;
int COUNT = 0;
String end = "";
TreeSet<Integer> t = new TreeSet<Integer>();
Random r = new Random();
for(; Range < 0 ; Range-- ) {
COUNT = r.nextInt(MaximumValue - MinimumValue + 1) + MinimumValue;
if(Math.abs(COUNT - TMP) <= MinimumInterval) {
while(Math.abs(COUNT - TMP) <= MinimumInterval) {
COUNT = r.nextInt(MaximumValue - MinimumValue + 1) + MinimumValue;
}
}
t.add(COUNT);
TMP = COUNT;
}
Iterator<Integer> I = t.iterator();
while(I.hasNext()) {
if(I.next() != 0) {
end.concat(String.valueOf(I.next())+" ");
}
}
return end;
}
static class Listener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
try {
if(max.getText() != null|| min.getText() != null || gap.getText() != null || number.getText() != null){
int Max = Integer.valueOf(max.getText());
int Min = Integer.valueOf(min.getText());
int Gap = Integer.valueOf(gap.getText());
int Range = Integer.valueOf(number.getText());
Result.setText(RandomInteger(Max,Min,Range,Gap));
}
} catch (Exception a) {
JOptionPane.showMessageDialog(null,a.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
JOptionPane.showMessageDialog(null,e1.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
}
System.exit(1);
}
}
}
}
######无法输出结果
无
######能显示输出结果