This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Cannot Resolve Symbol;set PreferredSize Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Cannot Resolve Symbol;set PreferredSize" Watch "Cannot Resolve Symbol;set PreferredSize" New topic
Author

Cannot Resolve Symbol;set PreferredSize

stab cooper
Greenhorn

Joined: Feb 07, 2006
Posts: 6
I am getting below error
cannot resolve symol: method setPreferred Size(java.awt.Dimension)

Error is for both locations (Classes). Funny thing is this code is working at University(I am a student) and have tried it on m home Pc and getting that error. I have tried other programs with the same method and I still get that error. Pliz help


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

class PopUpFrame extends JFrame implements ActionListener {
Container myPane;
JButton but;
JLabel lab;
int fc;

public PopUpFrame(int n) {
fc=n;
myPane = getContentPane();
myPane.setLayout(new FlowLayout());

lab = new JLabel("PopUp number "+fc);
myPane.add(lab);
but = new JButton("close"); myPane.add(but);
but.addActionListener(this);
setPreferredSize(new Dimension(140,140));
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
pack();
}
public void actionPerformed(ActionEvent e) {
setVisible(false);
dispose();
}
}
class ButtonFrame extends JFrame implements ActionListener {
Container myPane;
JButton but;
PopUpFrame pop;
int fcount;

public ButtonFrame() {
fcount=0;
myPane = getContentPane();
myPane.setLayout(new FlowLayout());

but = new JButton("New window");
myPane.add(but);
but.addActionListener(this);
setPreferredSize(new Dimension(140,70));
pack();
}
public void actionPerformed(ActionEvent e) {
fcount++;
pop = new PopUpFrame(fcount);
pop.setVisible(true);
}
}
public class PopUp1 {
public static void main(String args[]) {
ButtonFrame win = new ButtonFrame();
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.setVisible(true);
}
}
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

This method was added to the java.awt.Component class in JDK 1.5. Previous versions of Java didn't have it. Therefore, your code will only compile on JDK 1.5 or later.

The Javadoc API documents say "Since 1.5" on methods like this.


[Jess in Action][AskingGoodQuestions]
stab cooper
Greenhorn

Joined: Feb 07, 2006
Posts: 6
I have downloaded the JDK1.5.0 and did javac PopUp1.java and it compiled and then did c:\java PopUp1 and got this error

Exception in thread "main" java.lang.NoClassDefFoungError: PopUp1.

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

I have also tried another program and still get the same error.



class PopUpFrame extends JFrame implements ActionListener {
Container myPane;
JButton but;
JLabel lab;
int fc;

public PopUpFrame(int n) {
fc=n;
myPane = getContentPane();
myPane.setLayout(new FlowLayout());

lab = new JLabel("PopUp number "+fc);
myPane.add(lab);
but = new JButton("close"); myPane.add(but);
but.addActionListener(this);
setPreferredSize(new Dimension(140,140));
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
pack();
}
public void actionPerformed(ActionEvent e) {
setVisible(false);
dispose();
}
}
class ButtonFrame extends JFrame implements ActionListener {
Container myPane;
JButton but;
PopUpFrame pop;
int fcount;

public ButtonFrame() {
fcount=0;
myPane = getContentPane();
myPane.setLayout(new FlowLayout());

but = new JButton("New window");
myPane.add(but);
but.addActionListener(this);
setPreferredSize(new Dimension(140,70));
pack();
}
public void actionPerformed(ActionEvent e) {
fcount++;
pop = new PopUpFrame(fcount);
pop.setVisible(true);
}
}
public class PopUp1 {
public static void main(String args[]) {
ButtonFrame win = new ButtonFrame();
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.setVisible(true);
}
}
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Did you compile the source files (*.java) correctly into class files (*.class)? You have to set the classpath correctly. From the directory that contains PopUp1.class, type:

java -cp . PopUp1

The "-cp" switch sets the classpath. The "." means the current directory. This will make Java look in the current directory for class files.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot Resolve Symbol;set PreferredSize
 
Similar Threads
A calculator question!
Date and Time entry
How to resize JFrame programmatically?
Cant get BoxLayout to work right !!
button in jpanel should change background of jframe?