473,509 Members | 2,763 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GUI problems, Final Delcarations, Field Calculations

38 New Member
I have been working on this application for weeks now, it is almost finished, but I am getting errors that I am unable to work through.
Can someone look at my code and see if anything stands out that I might try correcting.
First, I am getting
Inventory2.java:187: actionPerformed(java.awt.event.ActionEvent) in cannot implement actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener; attempting to assign weaker access privileges; was public
final void actionPerformed(ActionEvent evt)

and have no idea what this means.
Second, I am getting
Inventory2.java:189: local variable currentCD is accessed from within inner class; needs to be declared final
valueField.setValue("$"+new Float(currentCD.getValue()));

and although I have some idea as to what this means, I have NO idea how to remedy it. Possibly the placement of my cast to the sub class, but again, I am unsure of any action to take.
//Instantiate object for JList
CdwArtist currentCD = (CdwArtist) listModel.get( currCD );
The class I am
working in is as follows: (There are two subclasses if anyone would like to see them, but I do not think they apply here.)
Any help at all would be welcome.
Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import javax.swing.*;
  5. import javax.swing.event.*;
  6. import java.text.*;
  7. import java.lang.*;
  8.  
  9. public class Inventory2 extends JFrame
  10. {
  11.     private JLabel cdNameLabel; // name label 
  12.     private JLabel artistLabel; // item number label 
  13.     private JLabel nstockLabel; // units in stock label 
  14.     private JLabel priceLabel; // price each label 
  15.     private JLabel itemLabel; // item number label 
  16.     private JLabel valueLabel; // value of that item label 
  17.     private JLabel rstkLabel; // cost to restock label 
  18.     private JLabel totalLabel; // total value of inventory label 
  19.     private JTextField cdNameField; // name display 
  20.     private JTextField artistField; // artist display 
  21.     private JFormattedTextField nstockField; // units in stock display 
  22.     private JFormattedTextField priceField; // price each display 
  23.     private JTextField itemField; // item number display 
  24.     private JFormattedTextField valueField; // value of that item display 
  25.     private JFormattedTextField rstkField; // cost to restock display
  26.     private JFormattedTextField totalField; // value of all inventory combine 
  27.     private NumberFormat nstockFormat; // format field and parse numbers 
  28.     private NumberFormat priceFormat; // format field and parse numbers 
  29.     private NumberFormat valueFormat; // format field and parse numbers 
  30.     private NumberFormat rstkFormat; // format field and parse numbers 
  31.     private NumberFormat totalFormat;
  32.     private JButton btnAdd; // first button 
  33.     private JButton btnPrev; // previous button 
  34.     private JButton btnNext; // next button 
  35.     private JButton btnDel; // last button 
  36.     private JPanel buttonJPanel; // JPanle to hold buttons 
  37.     private JPanel fieldJPanel; // JPanel to hold labels and displays 
  38.     private JPanel fontJPanel; // JPanel to display logo 
  39.     private int currCD; // current product display to use for button action 
  40.     private int i; // iterator 
  41.     private double total = 0; // variable for total inventory 
  42.     private JList Inventorylist; // JList to take place of old array
  43.     private DefaultListModel listModel;
  44.     private JScrollPane jScrollPanel;  
  45.  
  46.     public Inventory2() // create class and method to perform GUI build 
  47.     { 
  48.         initComponents(); 
  49.     } 
  50.  
  51.     private void initComponents() 
  52.     { 
  53.         // create label names 
  54.         cdNameLabel = new JLabel("CD Name:"); 
  55.         artistLabel = new JLabel("Artist:");
  56.         nstockLabel = new JLabel("In Stock:"); 
  57.         priceLabel = new JLabel("Each Item Cost:$"); 
  58.         itemLabel = new JLabel("Item Number:"); 
  59.         valueLabel = new JLabel("Value of Item Inventory:$"); 
  60.         rstkLabel = new JLabel("Cost to Re-Stock Item:$"); 
  61.         totalLabel = new JLabel("Total Value of Inventory:$"); 
  62.  
  63.         // initial fields
  64.         cdNameField = new JTextField(25);
  65.         cdNameField.setEditable(true);
  66.         artistField = new JTextField(15);
  67.         artistField.setEditable(true);
  68.         nstockField = new JFormattedTextField(nstockFormat);
  69.         nstockField.setEditable(true);
  70.         nstockField.setColumns(10);
  71.         priceField = new JFormattedTextField(priceFormat);
  72.         priceField.setEditable(true);
  73.         priceField.setColumns(10);
  74.         itemField = new JTextField(5);
  75.         itemField.setEditable(true);
  76.         valueField = new JFormattedTextField(valueFormat);
  77.         valueField.setEditable(true);
  78.         valueField.setColumns(10);
  79.         rstkField = new JFormattedTextField(rstkFormat);
  80.         rstkField.setEditable(true);
  81.         rstkField.setColumns(5);
  82.         totalField = new JFormattedTextField(totalFormat);
  83.         totalField.setColumns (10);
  84.         totalField.setEditable(true);
  85.  
  86.         // JList
  87.         jScrollPanel = new JScrollPane();
  88.         Inventorylist = new JList(); 
  89.  
  90.         //Instantiate object for JList
  91.         CdwArtist currentCD = (CdwArtist) listModel.get( currCD );
  92.  
  93.  
  94.        // add values to textFields
  95.     //    cdNameField.setText(currentCD.getcdName());
  96.     //    artistField.setText(currentCD.getArtist()); 
  97.     //    nstockField.setValue(new Float(currentCD.getValue()));
  98.     //    priceField.setValue(new Float("$"+curentrCD.getPrice()));
  99.     //    itemField.setText(currCD.getItem());
  100.     //    valueField.setValue(new Float("$" + currentCD.getValue()));
  101.     //    rstkField.setValue(new Float(currentCD.getRestock()));
  102.     //    totalField.setValue(new Float("$" + currentCD.getValue()));
  103.  
  104.  
  105.         // buttons 
  106.         btnAdd = new JButton(); 
  107.         btnNext = new JButton(); 
  108.         btnPrev = new JButton(); 
  109.         btnDel = new JButton(); 
  110.  
  111.         getContentPane().setLayout(new FlowLayout());
  112.  
  113.         setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  114.  
  115.         // place textFields and labels
  116.  
  117.         //artist
  118.         artistLabel.setText("Artist"); 
  119.         getContentPane().add(artistLabel); 
  120.  
  121.         artistField.setMinimumSize(new Dimension(75,19)); 
  122.         artistField.setPreferredSize(new Dimension(75,19));
  123.         getContentPane().add(artistField); 
  124.  
  125.         // cd name
  126.         cdNameLabel.setText("CD Name"); 
  127.         getContentPane().add(cdNameLabel); 
  128.  
  129.         cdNameField.setMinimumSize(new Dimension(75,19)); 
  130.         cdNameField.setPreferredSize(new Dimension(75,19));
  131.         getContentPane().add(cdNameField);
  132.  
  133.         // copies in stock
  134.         nstockLabel.setText("Copies In Stock"); 
  135.         getContentPane().add(nstockLabel); 
  136.  
  137.         nstockField.setMinimumSize(new Dimension(75,19)); 
  138.         nstockField.setPreferredSize(new Dimension(75,19));
  139.         getContentPane().add(nstockField); 
  140.  
  141.         //price of cd
  142.         priceLabel.setText("Price"); 
  143.         getContentPane().add(priceLabel); 
  144.  
  145.         priceField.setMinimumSize(new Dimension(75,19)); 
  146.         priceField.setPreferredSize(new Dimension(75,19));
  147.         getContentPane().add(priceField); 
  148.  
  149.         //item number of cd
  150.         itemLabel.setText("Item Number"); 
  151.         getContentPane().add(itemLabel); 
  152.  
  153.         itemField.setMinimumSize(new Dimension(75,19)); 
  154.         itemField.setPreferredSize(new Dimension(75,19));
  155.         getContentPane().add(itemField);; 
  156.  
  157.         // value of individual cd in stock
  158.         valueLabel.setText("Value"); 
  159.         getContentPane().add(valueLabel); 
  160.  
  161.         valueField.setMinimumSize(new Dimension(75,19)); 
  162.         valueField.setPreferredSize(new Dimension(75,19));
  163.         getContentPane().add(valueField); 
  164.  
  165.         // restocking fee
  166.         rstkLabel.setText("Restock Fee"); 
  167.         getContentPane().add(rstkLabel); 
  168.  
  169.         rstkField.setMinimumSize(new Dimension(75,19)); 
  170.         rstkField.setPreferredSize(new Dimension(75,19));
  171.         getContentPane().add(rstkField);
  172.  
  173.         // total value of inventory
  174.         totalLabel.setText("Total Inventory Value"); 
  175.         getContentPane().add(totalLabel); 
  176.  
  177.         totalField.setMinimumSize(new Dimension(75,19)); 
  178.         totalField.setPreferredSize(new Dimension(75,19));
  179.         getContentPane().add(totalField);    
  180.  
  181.  
  182.         //ADD listeners
  183.  
  184.         // listener to perform calc upon leaving the price field
  185.         priceField.addActionListener(new ActionListener()
  186.         {
  187.             final void actionPerformed(ActionEvent evt)
  188.             {
  189.             valueField.setValue("$"+new Float(currentCD.getValue()));
  190.             }
  191.         });
  192.  
  193.         btnAdd.setText("Add");
  194.         btnAdd.addActionListener(new ActionListener()
  195.         {
  196.             public void actionPerformed(ActionEvent evt)
  197.             {
  198.                 btnAddActionPerformed(evt);
  199.             }
  200.         });
  201.         getContentPane().add(btnAdd);
  202.  
  203.         // PREVIOUS
  204.         btnPrev.setText("Previous");
  205.         btnPrev.addActionListener(new ActionListener()
  206.         {
  207.             public void actionPerformed(ActionEvent evt)
  208.             {
  209.                 btnAddActionPerformed(evt);
  210.             }
  211.         });
  212.         getContentPane().add(btnPrev);
  213.  
  214.         // NEXT
  215.         btnNext.setText("Next");        btnNext.addActionListener(new ActionListener()
  216.         {
  217.             public void actionPerformed(ActionEvent evt)
  218.             {
  219.                 btnAddActionPerformed(evt);
  220.             }
  221.         });
  222.         getContentPane().add(btnNext);
  223.  
  224.         // DELETE
  225.         btnDel.setText("Delete");
  226.         btnDel.addActionListener(new ActionListener()
  227.         {
  228.             public void actionPerformed(ActionEvent evt)
  229.             {
  230.                 btnAddActionPerformed(evt);
  231.             }
  232.         });
  233.         getContentPane().add(btnDel);
  234.  
  235.         // new Jlist model
  236.         listModel = new DefaultListModel();
  237.         Inventorylist.setModel(listModel);
  238.  
  239.         jScrollPanel.setViewportView(Inventorylist);
  240.  
  241.         getContentPane().add(jScrollPanel);
  242.  
  243.         pack();
  244.     }// close
  245.  
  246.  
  247.         private void btnAddActionPerformed(ActionEvent evt)
  248.         {
  249.             // Create cd to add
  250.             CdwArtist cd = new CdwArtist(artistField.getText());
  251.             cd.setName(cdNameField.getText());    
  252.             cd.setItemno(Integer.parseInt(itemField.getText()));
  253.             cd.setNstock(Integer.parseInt(nstockField.getText()));
  254.             cd.setPrice(Float.parseFloat(priceField.getText()));
  255.             cd.setValue(Float.parseFloat(valueField.getText()));
  256.             cd.setTotal(Float.parseFloat(totalField.getText()));
  257.             cd.setRestock(Float.parseFloat(rstkField.getText()));    
  258.  
  259.             // Add cd to list
  260.             listModel.addElement(cd);
  261.  
  262.             // Clear the text fields after add
  263.             artistField.setText(null);
  264.             cdNameField.setText(null);    
  265.             itemField.setText(null);
  266.             nstockField.setText(null);
  267.          priceField.setText(null);
  268.             valueField.setText(null);
  269.             rstkField.setText(null);
  270.             totalField.setText(null);
  271.         }// end ADD
  272.  
  273.  
  274.         // run it
  275.         public static void main(String args[])
  276.         {
  277.         java.awt.EventQueue.invokeLater(new Runnable()
  278.             {
  279.             public void run()
  280.                 {
  281.                 new Inventory2().setVisible(true);
  282.                 }
  283.             });
  284.         }
  285.  
  286. } // close clas
Jul 25 '07 #1
3 1734
JosAH
11,448 Recognized Expert MVP
Here's one I found after skimming through your code: when you want to implement
an interface, your methods need to be public (not just final).

kind regards,

Jos
Jul 25 '07 #2
r035198x
13,262 MVP
Here's one I found after skimming through your code: when you want to implement
an interface, your methods need to be public (not just final).

kind regards,

Jos
I found one that didn't cause the compiler to complain but would be nice to correct as well: Do not set text of textfields to null, if you want to clear them set "" (the empty string) instead.
Jul 26 '07 #3
no1zson
38 New Member
great. I will give that a shot.
Thanks for the tip.
Jul 27 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2903
by: DJTB | last post by:
zodb-dev@zope.org] Hi, I'm having problems storing large amounts of objects in a ZODB. After committing changes to the database, elements are not cleared from memory. Since the number of...
9
1944
by: jason | last post by:
Access 2000 I need some help interogatting a table and extracting via ASP the final field in a row which has a value. In other words, I have a maximum of 10 fields but, at the user level he may...
3
1716
by: Mark Morton | last post by:
I'm writing an if statement for a UK credit card form validation script. Users who specify that their card is Switch need to enter either the issue number or the 'valid from' date. I'm trying to...
54
4492
by: tshad | last post by:
I have a function: function SalaryDisplay(me) { var salaryMinLabel = document.getElementById("SalaryMin"); salaryMinLabel.value = 200; alert("after setting salaryMinLabel = " +...
2
3889
by: John Baker | last post by:
Hi: Hi: I have a form which is based on a query, and is being used to update a table. It all works well, except for one thing. I have a number of unbound calculation fields (total value,...
4
1711
by: marti | last post by:
I've run into three problems trying to solve this one issue. Using VS2005 B2 & sql server 2000, I create a sqldatasource and bind a gridview to it. Everything looks good. However, if there is an...
18
3766
by: TORQUE | last post by:
Hi, Im wondering if anyone can help me with a problem. I have a form with more than 50 unbound fields. Some of the fields will be blank from time to time. This seems to be where im having...
2
1984
by: funkiejunkie | last post by:
Hello all, I posted a thread a while ago and was told to include the code so here it is. I still dont really get CSS, everything I have done has been blagged because I cant be bothered to read...
9
2604
Catalyst159
by: Catalyst159 | last post by:
I have a form which is used to calculate residential Floor Area Ratio (FAR). The form is structured into seven parts as follows: Part A: Maximum FAR and Floor Area: Part B: Gross Floor Area of...
0
7233
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7135
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7342
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7410
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.