Home » questions » Why there is error in my java program although i copied it directly from Deitel book.10 points if yo

Why there is error in my java program although i copied it directly from Deitel book.10 points if yo

2006-07-28 20:08:51, Category: Programming & Design
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 ); } }

Answers

  1. jasonjas

    On 2006-07-28 20:14:19


    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.
  2. SmartSpider

    On 2006-07-28 21:01:28


    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
  3. jacovkss2

    On 2006-07-28 20:48:10


    > 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?