Enjoy an Ads-Free Jets Insider - Become a Jets Insider VIP!
LATEST JI HEADLINES
TOP STORY
How to Decipher OTA Reports
 
5/17 : New Jets RB Goodson Arrested on Drugs and Weapons Charges
5/16 : Joe McKnight Doesn't Appreciate Questioning His Roster Spot
5/15 : QB Garrard to leave Jets
5/15 : uSTADIUM App Looks to Revolutionize Social Sports Media
Go Back   Jets Insider.com Forums > Beyond Sports > Business Networking Forum
Register FAQ Calendar Mark Forums Read

Business Networking Forum A place to introduce and network your business or service to fellow Jets Fans. NOTE: This is not a forum to spam. Illegal or inappropriate businesses will be deleted. The moderators reserve the right to delete any business they feel is inappropriate.

Reply
 
Thread Tools
Old 11-23-2008, 04:38 PM   #1
Area52
Shut the front door!
All League
 
Join Date: Jul 2008
Location: Pennsylvania
Posts: 699
Java Programming. Help please!

I am having problems with this code when I try to compile and was wondering if any one could give some advice. Here is the code.......................

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;



public class InventoryTest2
{
//main method begins execution of java application
public static void main(final String args[])
{

int index; // variable for looping
double total = 0; // variable for total inventory
final int dispDvd = 0; // variable for actionEvents

//instantiate an inventory object
final new Dvd[] DVDs = new Dvd[5];
// Instantiate objects for the array
for(int index = 0; index < DVDs.length; index++) //begin for loop
{

Dvd[] DVDs = new Dvd[4];
DVDs[0] = new Dvd("Superman", "111", 11, 12.99, "PG");
DVDs[1] = new Dvd("Batman Returns", "222", 9, 11.99, "PG-13");
DVDs[2] = new Dvd("Madagascar", "333", 10, 10.99, "G");
DVDs[3] = new Dvd("Cars", "444", 15, 13.99, "G");
}

for(int index = 0; index < DVDs.length; index++) //begin for loop
total += DVDs.length; // calculate total inventory cost

final JButton firstBtn = new JButton("First"); // first button
final JButton prevBtn = new JButton("Previous"); // previous button
final JButton nextBtn = new JButton("Next"); // next button
final JButton lastBtn = new JButton("Last"); // last button
final JLabel label; // logo
final JTextArea textArea; // text area for product list
final JPanel buttonJPanel; // panel to hold buttons

//JLabel constructor for logo
Icon logo = new ImageIcon("C:/dvdicon.gif"); // load logo
label = new JLabel(logo); // create logo label
label.setToolTipText("Company Logo"); // create tooltip

buttonJPanel = new JPanel(); // set up panel
buttonJPanel.setLayout( new GridLayout(1, 4)); //set layout
// add buttons to buttonPanel
buttonJPanel.add(firstBtn);
buttonJPanel.add(prevBtn);
buttonJPanel.add(nextBtn);
buttonJPanel.add(lastBtn);

textArea = new JTextArea(DVDs[3]+"\n"); // create textArea for product display

// add total inventory value to GUI
textArea.append("\nTotal value of Inventory "+new java.text.DecimalFormat("$0.00").format(total)+"\n \n");
textArea.setEditable(false); // make text uneditable in main display
JFrame invFrame = new JFrame(); // create JFrame container
invFrame.setLayout(new BorderLayout()); // set layout
invFrame.getContentPane().add(new JScrollPane(textArea), BorderLayout.CENTER); // add textArea to JFrame
invFrame.getContentPane().add(buttonJPanel, BorderLayout.SOUTH); // add buttons to JFrame
invFrame.getContentPane().add(label, BorderLayout.NORTH); // add logo to JFrame
invFrame.setTitle("GUI Inventory Program "); // set JFrame title
invFrame.setDefaultCloseOperation(JFrame.EXIT_ON_C LOSE); // termination command
//invFrame.pack();
invFrame.setSize(400, 400); // set size of JPanel
invFrame.setLocationRelativeTo(null); // set screem location
invFrame.setVisible(true); // display window


// assign actionListener and actionEvent for each button
firstBtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
dispDvd = 0;
textArea.setText(DVDs[dispDvd]+"\n");

} // end firstBtn actionEvent
}); // end firstBtn actionListener



//textArea.setText(DVDs[4]+"n");
prevBtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
dispDvd--;
if (dispDvd < 0)
{
dispDvd = 0;
}
//dispDvd = (DVDs.length+dispDvd-1) % DVDs.length;
textArea.setText(DVDs[dispDvd]+"\n");
} // end prevBtn actionEvent
}); // end prevBtn actionListener



lastBtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
dispDvd = DVDs.length-1;
textArea.setText(DVDs[dispDvd]+"\n");
} // end lastBtn actionEvent
}); // end lastBtn actionListener



nextBtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
dispDvd++;
if (dispDvd >= DVDs.length)
{
dispDvd = DVDs.length-1;
}
textArea.setText(DVDs[dispDvd]+"\n");
} // end nextBtn actionEvent
}); // end nextBtn actionListener


} // end main
} // end class InventoryTest2

Here is the error that I get............................................... ........

C:\School\Java Programming IT215\Misc Java Source Code\Inventory Program Part 5.java:31: illegal start of type
final new Dvd[] DVDs = new Dvd[5];
^
1 error

Tool completed with exit code 1

Any help would be greatly appreciated!
Area52 is offline   Reply With Quote
Sponsored Links
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Enjoy an Ads-Free Jets Insider - Become a Jets Insider VIP!

All times are GMT -4. The time now is 11:15 PM.



Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Copyright ©1999 - 2013, JetsInsider.com LTD