I've made a JFrame subclass, called World. It looks like this:
Help is another class, which has only a method to get random numbers, that works equal to Greenfoot.getRandomNumber.
When I use the main method, the JFrame opens and I get this error message:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Comparison method violates its general contract!
For higher width and higher height it doesn't finishes loading at all.
Has anyone knowledge about that?
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import java.awt.Color; public class World extends JFrame { private JLabel[][] pixel; private int width; private int height; public World(String title, int width, int height){ super(title); int border = 10; this.width = width; this.height = height; setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); int frameWidth = width+(2*border); int frameHeight = height+(2*border); setSize(frameWidth, frameHeight); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); int x = (d.width - getSize().width) / 2; int y = (d.height - getSize().height) / 2; setLocation(x, y); setResizable(false); Container cp = getContentPane(); cp.setLayout(null); //meins pixel = new JLabel[width][height]; for(int j = 0; j < height; j++){//y for(int i = 0; i < width; i++){//x JLabel a = new JLabel(); a.setBounds(i+border,j+border,1,1); cp.add(a); pixel[i][j] = a; System.out.println("x: "+i+" y: "+j); } } setVisible(true); System.out.println("Done"); } public void randomizeImage(){ for(int j = 0; j < height; j++)//y for(int i = 0; i < width; i++)//x if(pixel[i][j]!=null) pixel[i][j].setBackground(randomColor()); } public Color randomColor(){ return new Color(help.random(256),help.random(256), help.random(256),help.random(256)); } public static void main(String[] args){ World w = new World("World", 100, 100); w.randomizeImage(); } }