Solved

This came as a solution for a jlabel on top of the jpanel

Posted on 2004-04-02
5
201 Views
Last Modified: 2010-03-31
It didn't work a method cll from nowhere I guess! HELP



import java.awt.event.*;
import java.util.*;
import javax.swing.*;

public class MyClass4 extends JPanel {

  JLabel jLabel1;  
  ArrayList myArrayList = new ArrayList();

public MyClass4() {

     // Call it like this . . .
    jLabel = JLabel();

    setLayout(new GridLayout(0,3)); // Setting MY layout...
 
    add(jLabel1);  
    jLabel1.setText("Defensive Moves");
    setBackground(Color.white);

    looprow:
    for (int row=0; row<20; row++) {
    for(int col=0; col<3; col++) {
    int n=(20*col+row+1);
    if (n>50) break looprow;
    JCheckBox check = new JCheckBox("" + n);

    myArrayList.add(check);
    add(check);
    }
    }
}
}
0
Comment
Question by:Drop_of_Rain
  • 3
5 Comments
 
LVL 15

Expert Comment

by:Javatm
ID: 10746719
I didnt get the question can you clarify it ?
0
 

Author Comment

by:Drop_of_Rain
ID: 10746742
error message can't resolve method   jLabel = JLabel();
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10746751
It is because it should be like :

jLabel = new JLabel();

here it is :

import java.awt.event.*;
import java.util.*;
import javax.swing.*;

public class MyClass4 extends JPanel {

  JLabel jLabel1;  
  ArrayList myArrayList = new ArrayList();

public MyClass4() {

     // Call it like this . . .
    jLabel = new JLabel();

    setLayout(new GridLayout(0,3)); // Setting MY layout...
 
    add(jLabel1);  
    jLabel1.setText("Defensive Moves");
    setBackground(Color.white);

    looprow:
    for (int row=0; row<20; row++) {
    for(int col=0; col<3; col++) {
    int n=(20*col+row+1);
    if (n>50) break looprow;
    JCheckBox check = new JCheckBox("" + n);

    myArrayList.add(check);
    add(check);
    }
    }
}
}
0
 
LVL 5

Expert Comment

by:twobitadder
ID: 10748003
you're also mixing names, jLabel and jLabel1.
0
 
LVL 15

Accepted Solution

by:
Javatm earned 100 total points
ID: 10749800
> you're also mixing names, jLabel and jLabel1.

Joops, thanks I was confuse myself it should be :

import java.awt.event.*;
import java.util.*;
import javax.swing.*;

public class MyClass4 extends JPanel {

  JLabel jLabel1;  
  ArrayList myArrayList = new ArrayList();

public MyClass4() {

     // Call it like this . . .
    jLabel1 = new JLabel();

    setLayout(new GridLayout(0,3)); // Setting MY layout...
 
    add(jLabel1);  
    jLabel1.setText("Defensive Moves");
    setBackground(Color.white);

    looprow:
    for (int row=0; row<20; row++) {
    for(int col=0; col<3; col++) {
    int n=(20*col+row+1);
    if (n>50) break looprow;
    JCheckBox check = new JCheckBox("" + n);

    myArrayList.add(check);
    add(check);
    }
    }
}
}

Hope that helps . . .
Javatm
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now