473,396 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Using loops to add labels to a frame

I've been trying to use loops to add labels to a frame. I was able to get the program to compile but the labels aren't showing up.

import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;

public class Assignment3 extends JFrame {
private ImageIcon cross = new ImageIcon("Assignment3/cross.gif");
private ImageIcon not = new ImageIcon("Assignment3/not.gif");
int count = 0;


public static void main(String[] args)
{
Assignment3 frame = new Assignment3();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setTitle("Exercise 12_7");
frame.setSize(200, 200);
frame.setVisible(true);
}

public Assignment3() {
setLayout(new GridLayout(1, 4, 5, 5));

while (count > 10) {

int number1 = (int)(Math.random() * 3);

if (number1 == 0) {
add(new JLabel());
}

else if (number1 == 1) {
add(new JLabel(cross));
}

else if (number1 == 2) {
add(new JLabel(not));
}
count++;


}

}

}
Feb 9 '07 #1
1 3097
r035198x
13,262 8TB
I've been trying to use loops to add labels to a frame. I was able to get the program to compile but the labels aren't showing up.

import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;

public class Assignment3 extends JFrame {
private ImageIcon cross = new ImageIcon("Assignment3/cross.gif");
private ImageIcon not = new ImageIcon("Assignment3/not.gif");
int count = 0;


public static void main(String[] args)
{
Assignment3 frame = new Assignment3();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setTitle("Exercise 12_7");
frame.setSize(200, 200);
frame.setVisible(true);
}

public Assignment3() {
setLayout(new GridLayout(1, 4, 5, 5));

while (count > 10) {

int number1 = (int)(Math.random() * 3);

if (number1 == 0) {
add(new JLabel());
}

else if (number1 == 1) {
add(new JLabel(cross));
}

else if (number1 == 2) {
add(new JLabel(not));
}
count++;


}

}

}
Try doing jframe.setVisible(true) after adding the components if that does not work then call repaint().
Feb 9 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: cody | last post by:
for (int serie=1; serie < TurnierGruppe.AktuelleSerie.Serie; serie++) { //outer: here is works foreach (Tischbesetzung tb in TurnierGruppe.Serien.Tischebesetzungen) { for (int i=0;...
77
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html The above link shows that C# is 450% slower on something as simple as a nested loop....
12
by: Don Juan | last post by:
I have a simple html document I have been using for some time on my (i.e.) abc.com domain that uses cookies. I recently purchased a new domain name and set up a service to redirect my new domain...
9
by: liorm | last post by:
Hi folks, I need to write a short program which gets a few parameters and draws a diagram in the text file. Basically what I need is a guidance on how I put stream indicator to the required...
6
by: Wijaya Edward | last post by:
Can we make loops control in Python? What I mean is that whether we can control which loops to exit/skip at the given scope. For example in Perl we can do something like: OUT: foreach my $s1...
0
by: PHENOM | last post by:
How do i paste labels & buttons on a frame in java
13
by: jkimbler | last post by:
As part of our QA of hardware and firmware for the company I work for, we need to automate some testing of devices and firmware. Since not everybody here knows C#, I'm looking to create a new...
1
by: viv1tyagi | last post by:
Hi everyone ! ! ! I'm just a month old in the world of Python and trying to develop an application using Tkinter in which a new window pops out on a particular button press.The code for this new...
8
by: Nathan Sokalski | last post by:
I have several nested For loops, as follows: For a As Integer = 0 To 255 For b As Integer = 0 To 255 For c As Integer = 0 To 255 If <Boolean ExpressionThen <My CodeElse Exit For Next If Not...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.