Why There Is Error In My Java Program Although I Copied It Directly From Deitel Book.10 Points If Yo
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.SwingConstants;
public class AnimalCategory extends JFrame
{
// set up GUI
public AnimalCategory()
super(" AnimalClass ");
// create JTabbedPane
JTabbedPane tabbedPane = new JTabbedPane();
// set up panel and add it to JTabbedPane
JLabel label1 = new JLabel("Tigers", SwingConstants.CENTER);
JPanel panel1 = new JPanel(); // create first panel
panel1.setBackground(Color.Blue); //set background to blue
panel1.add( label1 ); // add label to panel
tabbedPane.addTab("Tab One", null, panel1, "First Panel");
JLabel label2 = new JLabel("Elephant", SwingConstants.CENTER);
// create second panel
JPanel panel2 = new JPanel();
panel2.setBackground(Color.Yellow); //set background to yellow
// add label to panel
panel2.add(label2);
*/ continue
tabbedPane.addTab("Tab Two", null, panel2, "Second Panel");
JLabel label3 = new JLabel("Elephant", SwingConstants.CENTER);
// create third panel
JPanel panel3 = new JPanel();
panel3.setBackground(Color.Green); //set background to green
// add label to panel
panel3.add(label3);
tabbedPane.addTab("Tab three", panel3, "Third Panel");
add( tabbedPane );
}
}
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.SwingConstants;
public class AnimalCategory extends JFrame
{
// set up GUI
public AnimalCategory()
super(" AnimalClass ");
// create JTabbedPane
JTabbedPane tabbedPane = new JTabbedPane();
// set up panel and add it to JTabbedPane
JLabel label1 = new JLabel("Tigers", SwingConstants.CENTER);
JPanel panel1 = new JPanel(); // create first panel
panel1.setBackground(Color.Blue); //set background to blue
panel1.add( label1 ); // add label to panel
tabbedPane.addTab("Tab One", null, panel1, "First Panel");
JLabel label2 = new JLabel("Elephant", SwingConstants.CENTER);
// create second panel
JPanel panel2 = new JPanel();
panel2.setBackground(Color.Yellow); //set background to yellow
// add label to panel
panel2.add(label2);
*/ continue
tabbedPane.addTab("Tab Two", null, panel2, "Second Panel");
JLabel label3 = new JLabel("Elephant", SwingConstants.CENTER);
// create third panel
JPanel panel3 = new JPanel();
panel3.setBackground(Color.Green); //set background to green
// add label to panel
panel3.add(label3);
tabbedPane.addTab("Tab three", panel3, "Third Panel");
add( tabbedPane );
}
}
No... there is no need of a ; after the keyword new - its actually one line of code so the semicolon is needed at the end of the parentheses ie
JTabbedPane tabbedPane = new JTabbedPane();
The keyword new is used to create an object instance.
Rarveen paria zarasu - I replied to your email... so I guess I should get 10 points ;). You can ask me further questions in the email - your_taurean@yahoo.com
JTabbedPane tabbedPane = new JTabbedPane();
The keyword new is used to create an object instance.
Rarveen paria zarasu - I replied to your email... so I guess I should get 10 points ;). You can ask me further questions in the email - your_taurean@yahoo.com
I now very little about Java and only know what I learned from my class, but near the beginning of the program with
'// create JTabbedPane
JTabbedPane tabbedPane = new
JTabbedPane(); '
Is it supposed to be
// create JTabbedPane
JTabbedPane tabbedPane = new;
JTabbedPane();
Maybe?? All I did was add a ';' to the end of the second line on that piece.
'// create JTabbedPane
JTabbedPane tabbedPane = new
JTabbedPane(); '
Is it supposed to be
// create JTabbedPane
JTabbedPane tabbedPane = new;
JTabbedPane();
Maybe?? All I did was add a ';' to the end of the second line on that piece.
No... there is no need of a ; after the keyword new - its actually one line of code so the semicolon is needed at the end of the parentheses ie
JTabbedPane tabbedPane = new JTabbedPane();
The keyword new is used to create an object instance.
Rarveen paria zarasu - I replied to your email... so I guess I should get 10 points ;). You can ask me further questions in the email - your_taurean@yahoo.com
JTabbedPane tabbedPane = new JTabbedPane();
The keyword new is used to create an object instance.
Rarveen paria zarasu - I replied to your email... so I guess I should get 10 points ;). You can ask me further questions in the email - your_taurean@yahoo.com
> All I did was add a ';' to the end of the second line on that piece.
I know almost nothing about Java, but I know THAT's not correct. Time to take that class again, Jasonjas? :-)
Rarveen: have you visted the publisher's website yet, and looked for errata to the book?
I know almost nothing about Java, but I know THAT's not correct. Time to take that class again, Jasonjas? :-)
Rarveen: have you visted the publisher's website yet, and looked for errata to the book?