-1
我想通过使用无限的for loop
在java中的JFRAME中打印随机Unicode字符。打印java中的随机Unicode字符thorugh infinite FOR循环
我是java编程的新手,我希望答案不是太复杂。
这是代码,使远
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class Matrix extends JFrame{
private static final int NUMBER_OF_REPS = 0;
public static void main(String[] args) {
int a;
Random rand=new Random();
for(a=1;a>0;)
{
JLabel lbl=new JLabel();
lbl.setForeground(Color.GREEN);
lbl.setFont(new Font("MS Arial Unicode",Font.BOLD,12));
lbl.setText("\\u30"+Integer.toHexString(rand.nextInt(96) + 160));
}
JFrame frame=new JFrame();
frame.setLocationRelativeTo(null);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.getContentPane().setBackground(Color.BLACK);
//error! lbl cannot be resolved to a variable
frame.getContentPane().add(lbl);
frame.getContentPane().setLayout(new FlowLayout());
}
}
这将是有益的,如果你提供了你尝试过的东西的细节 – vembutech 2014-11-06 15:40:47
新程序员的一般建议:把你的问题分解成更小的问题,并专注于独立解决问题。在这种情况下,可以将其分解为两个问题:1.用'for'循环生成随机Unicode字符。 2.创建一个'JFrame'并在其中写入文本。然后,将这些问题分解成更小的问题。这将帮助你在小步骤中学习,并提出清晰,简洁的问题。祝你好运! – ZoogieZork 2014-11-06 17:36:35
我搜索了几个小时,但找不到具体的答案,我正在寻找;我想创建一个程序,可以随机生成并显示unicode字符在jframe中使用循环。 – 2014-11-07 16:07:36