Drop_of_Rain
asked on
NullPointException error don't see it
It happen here: add(jLabel1); jLabel1.setText("Defensive Moves"); setBackground(Color.white) ;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class MyClass4 extends JPanel {
JLabel jLabel1;
ArrayList myArrayList = new ArrayList();
// Constructor
public MyClass4() {
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); // Adding it to ME
}
}
}
}
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class MyClass4 extends JPanel {
JLabel jLabel1;
ArrayList myArrayList = new ArrayList();
// Constructor
public MyClass4() {
setLayout(new GridLayout(0,3)); // Setting MY layout...
add(jLabel1); jLabel1.setText("Defensive
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); // Adding it to ME
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Friend;
You need to also call the jLabel after you had declared it like :
import java.awt.*;
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);
}
}
}
}
Hope that helps . . .
Javatm
You need to also call the jLabel after you had declared it like :
import java.awt.*;
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
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
Your 2 fast you think you havent seen my solution.
ASKER
Error can't resolve method jLabel1()
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);
}
}
}
}
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
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);
}
}
}
}
jLabel = JLabel();
should be
jLabel = new JLabel(); //to initialise a new JLabel you use the new operator.
should be
jLabel = new JLabel(); //to initialise a new JLabel you use the new operator.
it should be jLabel1 = new jLabel() actually, you don't have any object called jlabel
http://www.objects.com.au/staff/mick