• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is wrong with code...please help!  RSS feed

 
Philip Alcala
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm getting "cannot find symbol" errors and "java.awt.Component cannot be applied to ()" errors.
What does this mean? Below is code that's giving me the errors.
Any help would be greatly appreciated.



import javax.swing.*; //for JRadioButton, JGroupButton,JPanel;
import java.awt.*;
import java.awt.event.*;

public class JTabbedDemo extends JFrame
{
JTabbedPane jtp = new JTabbedPane(SwingConstants.LEFT);

//Here are our three panel classes.
VacationPanel vp = new VacationPanel();
MoviePanel mp = new MoviePanel();
PasswordPanel pp = new PasswordPanel();

//We make a separate panel here that is a member of this class.
JPanel summaryPanel = new JPanel();

JButton summaryButton = new JButton("Summary");

JLabel vacationLabel = new JLabel();
JLabel movieLabel = new JLabel();
JLabel passwordLabel = new JLabel();

JButton colorButton = new JButton("Color?");
Color buttonsColor = new Color(0.75f, 0.75f, 0.75f);
public JTabbedDemo()
{
Container canvas = getContentPane();
canvas.add(jtp);

//JTabbedPane has several add() and addTab() methods.
//Here we pass in the title of the tab, null indicating no icon,
//the Component, and the tooltip text.

jtp.addTab("Vacation", null, vp, "Vacation locale?");
jtp.addTab("Movies", null, mp, "Movie preference?");
jtp.addTab("Password",null, pp, "Tell me your password");

//For the color and summary we just add the title and component.
//No icon, no tooltip.
jtp.addTab(" Pick a color", colorButton);

fixUpSummaryPanel();
jtp.addTab("Summary", summaryPanel);

colorButton.addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent ae)
{
buttonsColor = JColorChooser.showDialog(null,
"Pick a color for this button", buttonsColor);
colorButton.setBackground(buttonsColor);
}
} );


this.setSize(400,200);
this.setTitle("JTabbedDemo Program ");
this.setVisible();
}

public void fixUpSummaryPanel()
{
summaryPanel.setLayout( new FlowLayout() );
summaryPanel.add(summaryButton);
summaryPanel.add(vacationLabel);
summaryPanel.add(movieLabel);
summaryPanel.add(passwordLabel);

summaryButton.addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent ae)
{
vacationLabel.setText(vp.getVacationChoice() );
movieLabel.setText( mp.getMovieChoice() );
passwordLabel.setText( pp.getPassword() );
summaryButton.setBackground(buttonsColor);
}
} );
}

public static void main( String args[] )
{
JTabbedDemo app = new JTabbedDemo();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have class definitions for the panels?
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Errors in the following lines:


Solution: You need to import these classes


Solution: Should be setVisible(true);
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error "cannot find symbol: <name>" means that in the source code you are using a name of a variable or class that does not exist at the place where you use it. Look closely at the error message. It mentions the name of the thing that the compiler can't find, and also the exact line in your source code where the error happens. Look at that line in your source code and find out what's missing.

Like Keith and Lynette are saying, you are using classes such as VacationPanel, MoviePanel and PasswordPanel in your source code. Do you have to source files or class files for these in the right place?

Errors like "java.awt.Component cannot be applied to ()" most likely mean that you are trying to call a method with the wrong parameters, or that you are trying to do an operation that can't be done with the variables you're trying to use it on. Again, look carefully at the error message, it tells you exactly where in your source (in which line) code the error is.
 
Philip Alcala
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for the advise. I really need to learn to slow down when compiling. The errors are clear now.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!