|
#1
|
|||
|
|||
|
NetBeans Java Help
Hi Guys,
Working on a class at the moment in NetBeans however I have a problem with a section of code; Code:
public void init() {
itemList = new ArrayList();
GUI gui1 = new GUI();
getContentPane().add(gui1, "Center");
}
Code:
NetBeansProjects\ToDoList\src\ToDoList.java:26: cannot find symbol
symbol : method add(ToDoList.GUI,java.lang.String)
location: class java.awt.Container
getContentPane().add(gui1, "Center");
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
Code:
/* Small application implementing a To-Do List.
* Uses a mobile phone-like interface.
*/
import java.awt.Container;
import java.util.ArrayList;
import java.util.Collections;
import javax.swing.JApplet;
public class ToDoList extends JApplet {
// first we create an instance of this class
class GUI{}
public ToDoList() {
// create a graphical user interface,
// passing it a reference to this tdl program object
// initialisation goes here:
}
public void init() {
itemList = new ArrayList();
GUI gui1 = new GUI();
getContentPane().add(gui1, "Center");
}
public ArrayList getList() {
// dummy return value of an empty list,
// just to get the program to compile initially
return itemList;
}
public ArrayList addToList(String s) {
itemList.add(s);
return itemList;
}
public ArrayList getSortedList() {
// dummy return value of an empty list,
// just to get the program to compile initially
Collections.sort(itemList);
return itemList;
}
public ArrayList performReverse() {
// dummy return value of an empty list,
// just to get the program to compile initially
Collections.reverse(itemList);
return itemList;
}
public ArrayList performDeletion(int i) {
// dummy return value of an empty list,
// just to get the program to compile initially
if(i < itemList.size())
itemList.remove(i);
return itemList;
}
public ArrayList performSwap(int i) {
// dummy return value of an empty list,
// just to get the program to compile initially
if(i < itemList.size() && itemList.size() >=2)
{
String s = (String)itemList.remove(i);
if(i < itemList.size())
itemList.add(i + 1, s);
else
itemList.add(itemList.size() - 1, s);
}
return itemList;
}
private GUI gui;
private ArrayList itemList;
}
|
|
#2
|
|||
|
|||
|
Hi,
First of this problem has got nothing to do with NetBeans. Please use correct heading for the problem description. Coming to the compilation error, this is due to the reason that wrong method signature is being used here. The correct signature is: Code:
add(String name, Component comp) Code:
Component For example : Code:
class GUI extends Component {}
|
|
#3
|
|||
|
|||
|
Thanks for your reply. I have declared;
Code:
import java.awt.Component; Code:
public class GUI extends Component {
public void init() {
itemList = new ArrayList();
GUI gui1 = new GUI();
add(Component, gui1);
}
}
|
|
#4
|
|||
|
|||
|
Hi,
Please pay attention to the method signature you are trying to use: Code:
add(String name, Component comp) Code:
java.lang.String The second argument should be of type Code:
java.awt.Component Code:
class GUI extends Component In your case the second argument is rightly specified as 'gui1', but its the first argument, which should be a String. Regards. |
|
#5
|
|||
|
|||
|
Hi,
Thanks for all your help, I'm very much a beginner with this! I seem to have fixed all the errors however now my applet just runs as a blank window, no graphic displayed. I've included all of the latest code below; ToDoList.java Code:
/* Small application implementing a To-Do List.
* Uses a mobile phone-like interface.
*/
import java.lang.String;
import java.awt.Component;
import java.util.ArrayList;
import java.util.Collections;
import javax.swing.JApplet;
public class ToDoList extends JApplet {
// first we create an instance of this class
public ToDoList() {
// create a graphical user interface,
// passing it a reference to this tdl program object
// initialisation goes here:
}
class GUI extends Component {
public void init() {
itemList = new ArrayList();
GUI gui1 = new GUI();
getContentPane().add(gui1, "Center");
}
}
public ArrayList getList() {
// dummy return value of an empty list,
// just to get the program to compile initially
return itemList;
}
public ArrayList addToList(String s) {
itemList.add(s);
return itemList;
}
public ArrayList getSortedList() {
// dummy return value of an empty list,
// just to get the program to compile initially
Collections.sort(itemList);
return itemList;
}
public ArrayList performReverse() {
// dummy return value of an empty list,
// just to get the program to compile initially
Collections.reverse(itemList);
return itemList;
}
public ArrayList performDeletion(int i) {
// dummy return value of an empty list,
// just to get the program to compile initially
if(i < itemList.size())
itemList.remove(i);
return itemList;
}
public ArrayList performSwap(int i) {
// dummy return value of an empty list,
// just to get the program to compile initially
if(i < itemList.size() && itemList.size() >=2)
{
String s = (String)itemList.remove(i);
if(i < itemList.size())
itemList.add(i + 1, s);
else
itemList.add(itemList.size() - 1, s);
}
return itemList;
}
private GUI gui;
private ArrayList itemList;
public static void main(String args[])
{
}
}
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Java book | Lou | Java | 9 | 09-19-2007 06:58 AM |
| Java vs. .Net. A questionnaire | Basil | .NET | 1 | 05-13-2005 07:46 AM |
| NETBEANS IDE VERSION 3.2 RELEASED | George Dvorak | Open Source | 0 | 05-06-2001 09:01 AM |
| Re: VB vs. Visual Age for Java | JJ | Enterprise | 1 | 07-06-2000 05:50 AM |