Java JFrame multiple objects

+2 Hristijan Ilieski · November 22, 2014
Can someone explain me how to add multiple objects in JFrame? As I know I need to use custom layouts, but I can't figure how to use them. Also, the size of the window is not setting to 100x100..

public class Window extends JFrame{

private static final long serialVersionUID = 1L;
private static final String NAME = "Macedonia";
private static final Color BG_COLOR = Color.DARK_GRAY;
private Figura f[];

public Window(){
JFrame frame = new JFrame(NAME);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBackground(BG_COLOR);
frame.setSize(100, 100);
f = new Figura[30];
for(int i=0; i<f.length; i++){

}
f[0] = new Figura(600, 500, BG_COLOR);
f[0].setSizeOfRect(40, 40);
f[0].setPosition(10, 10);
f[0].setColor(Color.RED);

f[1] = new Figura(600, 500, BG_COLOR);
f[1].setSizeOfRect(40, 40);
f[1].setPosition(60, 10);
f[1].setColor(Color.BLUE);

frame.add(f[0]);
frame.add(f[1]);

frame.pack();
frame.setVisible(true);
}

}

I simply need to draw more images on my window, is there any way not to use JPanel? I simply need a coordinate system and nothing more.....

Post a Reply

Replies

Oldest  Newest  Rating
0 Hristijan Ilieski · November 22, 2014
I agree, but the problem with the flowlayout is that I can't draw multiple object... I am now trying with grid layout, but it wont work as I want...
  • 1

Java / Android Development

107,147 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator