• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot Resolve Symbol;set PreferredSize

 
stab cooper
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
stab cooper
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15480
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic