Results 1 to 13 of 13
Thread: makeButton errors
- 08-09-2008, 07:22 PM #1
Member
- Join Date
- Jul 2008
- Posts
- 43
- Rep Power
- 0
makeButton errors
I am doing an Inventory Program that requires GUI buttons. Below are the errors that I am getting. The errors seem to all be related to my makeButton method. I am not sure how to fix my program to get these buttons to work. Can someone please help me? In addition, I have a ActionListener message I have no clue on how to fix. If anyone can help me fix these errors, I would be much appreciative. Thank you!
Errors
InventoryProgramPart5.java:196: RunInv is not abstract and does not override abs
tract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.Actio
nListener
class RunInv extends JFrame implements ActionListener
^
InventoryProgramPart5.java:242: cannot find symbol
symbol : method makeTheDataItems()
location: class RunInv
makeTheDataItems();
^
InventoryProgramPart5.java:266: cannot find symbol
symbol : method makeButton(java.lang.String)
location: class RunInv
JButton first = makeButton( "First" );
^
InventoryProgramPart5.java:267: cannot find symbol
symbol : method makeButton(java.lang.String)
location: class RunInv
JButton next = makeButton( "Next" );
^
InventoryProgramPart5.java:268: cannot find symbol
symbol : method makeButton(java.lang.String)
location: class RunInv
JButton previous = makeButton( "Previous" );
^
InventoryProgramPart5.java:269: cannot find symbol
symbol : method makeButton(java.lang.String)
location: class RunInv
JButton last = makeButton( "Last" );
^
InventoryProgramPart5.java:270: cannot find symbol
symbol : method makeButton(java.lang.String)
location: class RunInv
JButton exit = makeButton( "Exit" );
^
InventoryProgramPart5.java:273: cannot find symbol
symbol : method makeButton(java.lang.String)
location: class RunInv
JButton add = makeButton( "Add" );
^
InventoryProgramPart5.java:274: cannot find symbol
symbol : method makeButton(java.lang.String)
location: class RunInv
JButton delete = makeButton( "Delete" );
^
InventoryProgramPart5.java:275: cannot find symbol
symbol : method makeButton(java.lang.String)
location: class RunInv
JButton modify = makeButton( "Modify" );
^
InventoryProgramPart5.java:276: cannot find symbol
symbol : method makeButton(java.lang.String)
location: class RunInv
JButton save = makeButton( "Save" );
^
InventoryProgramPart5.java:277: cannot find symbol
symbol : method makeButton(java.lang.String)
location: class RunInv
JButton find = makeButton( "Find" );
^
12 errors
Java Code:// CheckPoint: InventoryProgramPart5.java // Week 8 // This program calculates inventory value import java.util.Arrays; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class InventoryProgramPart5 { public static void main( String args[] ) { double restockingFee = 0.05; manufacturer[] inventory = new manufacturer[5]; // array of 5 inventory[0] = new manufacturer ( "notepads", restockingFee, "4000", "Ampad", 60, 2.75 ); inventory[1] = new manufacturer ( "pencils", restockingFee, "5000", "Bic", 75, 1.25 ); inventory[2] = new manufacturer ( "folders", restockingFee, "2000", "3M", 30, 4.75 ); inventory[3] = new manufacturer ( "envelopes", restockingFee, "1000", "Universal", 15, 5.25 ); inventory[4] = new manufacturer ( "markers", restockingFee, "3000", "Sanford", 45, 3.50 ); manufacturer temp[] = new manufacturer[1]; for( int j = 0; j < inventory.length - 1; j++ ) { for( int k = 0; k < inventory.length - 1; k++ ) { if( inventory[k].getItemName().compareToIgnoreCase ( inventory[k+1].getItemName() ) > 0 ) { temp[0] = inventory[k]; inventory[k] = inventory[k+1]; inventory[k+1] = temp[0]; } // end if } // end for } // end for javax.swing.JTextArea ta = new javax.swing.JTextArea( 10, 25 ); for( int j = 0; j < inventory.length; j++ ) { // System.out.println( inventory[j].toString() );<----------------- ta.append( inventory[j].toString()+"\n" ); } // end for // System.out.printf( "Total value of all inventory = $%.2f", // Inventory.etTotalValueOfAllInventory( inventory ) ); // return; // <------------------above line and this line ta.append("Total value of all inventory = "+product.getTotalValueOfAllInventory(inventory)); javax.swing.JFrame frame = new javax.swing.JFrame(); frame.getContentPane().add( new javax.swing.JScrollPane(ta) ); frame.pack(); frame.setLocationRelativeTo( null ); frame.setDefaultCloseOperation( javax.swing.JFrame.EXIT_ON_CLOSE ); frame.setVisible( true ); } // end main } // end class InventoryProgramPart5 // The product class class product { String productNumber; String name; int numberOfUnits; double pricePerUnit; // create a new instance of Inventory // main constructor for the class product( String Item_Number, String Item_Name, int Items_in_Stock, double Item_Price ) { productNumber = Item_Number; name = Item_Name; numberOfUnits = Items_in_Stock; pricePerUnit = Item_Price; } // end constructor // sets the product name public void setItemName( String Item_Name ) { name = Item_Name; } // sets the product number public void setItemNumber( String Item_Number ) { productNumber = Item_Number; } // sets the number of units in stock public void setItemsInStock( int Items_in_Stock ) { numberOfUnits = Items_in_Stock; } // sets the price of the product public void setItemPrice( double Item_Price ) { pricePerUnit = Item_Price; } // returns product name public String getItemName() { return name; } // returns product number public String getItemNumber() { return productNumber; } // returns units in stock public int getItemsInStock() { return numberOfUnits; } // returns product price public double getItemPrice() { return pricePerUnit; } // returns the total value of inventory public double getInventoryValue() { return pricePerUnit * numberOfUnits; } public static double getTotalValueOfAllInventory( product[] inv ) { double tot = 0.0; for( int i = 0; i < inv.length; i++ ) { tot += inv[i].getInventoryValue(); } return tot; } public String toString() { StringBuffer sb = new StringBuffer(); sb.append( "Product Name: \t" ).append( name ).append( "\n" ); sb.append( "Product Number: \t" ).append( productNumber ).append( "\n" ); sb.append( "Units in Stock: \t" ).append( numberOfUnits ).append( "\n" ); sb.append( "Unit Price: \t" ).append( String.format( "$%.2f%n", pricePerUnit ) ); sb.append( "Inventory Value: \t" ).append(String.format("$%.2f%n", this.getInventoryValue())); return sb.toString(); } // end toString } // end class product class manufacturer extends product { // manufacturer of product String manufacturer; // percentage added to base price as restocking fee double restockingFee; // actual inventory value will be the base inventory value plus // the base inventory value times this amount ( value + ( value * restockingFee ) ) public manufacturer( String Item_Name, double restockingFee, String Item_Number, String manufacturer, int Items_in_Stock, double Item_Price ) { super( Item_Number, Item_Name, Items_in_Stock, Item_Price); this.manufacturer = manufacturer; this.restockingFee = restockingFee; } // returns inventory value plus the restocking fee public double getInventoryValue() { return super.getInventoryValue() + ( super.getInventoryValue() * restockingFee ); } // end getInventoryValue public String toString() { StringBuffer sb = new StringBuffer( "Manufacturer: \t" ).append( manufacturer ).append( "\n" ); sb.append( super.toString() ); return sb.toString(); } // end toString } // end class manufacturer class RunInv extends JFrame implements ActionListener { // utility class for displaying the picture private class MyPanel extends JPanel { ImageIcon image = new ImageIcon( "HTML.jpg" ); int width = image.getIconWidth(); int height = image.getIconHeight(); long angle = 0; public MyPanel() { super(); } public void paintComponent( Graphics g ) { super.paintComponent(g); Graphics2D g2d = ( Graphics2D )g; g2d.rotate( Math.toRadians(angle), 200+width/2, 90+height/2 ); g2d.drawImage( image.getImage(), 5, 5, this ); g2d.dispose(); } } // end class MyPanel int currentIndex; // currently displayed Item manufacturer[] inventory = new manufacturer[5]; JLabel name; JLabel number; JLabel manufacturer; JLabel units; JLabel price; JLabel fee; JLabel totalValue; JTextField nameField = new JTextField(20); JTextField numberField = new JTextField(20); JTextField manufacturerField = new JTextField(20); JTextField unitsField = new JTextField(20); JTextField priceField = new JTextField(20); JTextField totalValueField = new JTextField(20); JPanel display; JPanel displayHolder; JPanel panel; public RunInv() { makeTheDataItems(); setSize( 700, 300 ); setTitle( "Inventory Program" ); // make the panels display = new JPanel(); JPanel other = new JPanel(); JPanel picture = new MyPanel(); JPanel buttons = new JPanel(); JPanel centerPanel = new JPanel(); displayHolder = new JPanel(); display.setLayout( new GridLayout( 3, 3 ) ); other.setLayout( new GridLayout( 2, 1 ) ); // make the labels name = new JLabel( "Product Name:" ); number = new JLabel( "Product Number:" ); manufacturer = new JLabel( "Manufacturer:" ); units = new JLabel( "Units in Stock:" ); price = new JLabel( "Price :$" ); fee = new JLabel( "Fee :$" ); totalValue = new JLabel( "Total value : $" ); // make the buttons JButton first = makeButton( "First" ); JButton next = makeButton( "Next" ); JButton previous = makeButton( "Previous" ); JButton last = makeButton( "Last" ); JButton exit = makeButton( "Exit" ); // other buttons JButton add = makeButton( "Add" ); JButton delete = makeButton( "Delete" ); JButton modify = makeButton( "Modify" ); JButton save = makeButton( "Save" ); JButton find = makeButton( "Find" ); // add the labels to the display panel display.add( name ); display.add( number ); display.add( manufacturer ); display.add( units ); display.add( price ); display.add( fee ); display.add( totalValue ); // add the buttons to the buttonPanel buttons.add( first ); buttons.add( previous ); buttons.add( next ); buttons.add( last ); buttons.add( exit ); // add the picture panel and display to the centerPanel displayHolder.add( display ); centerPanel.setLayout( new GridLayout( 2, 1 ) ); centerPanel.add( picture ); centerPanel.add( displayHolder ); other.add( buttons ); JPanel forAdd = new JPanel(); // add the other buttons to this panel forAdd.add( find ); forAdd.add( add ); forAdd.add( modify ); forAdd.add( delete ); forAdd.add( save ); other.add( forAdd ); // add the panels to the frame getContentPane().add( centerPanel, "Center" ); getContentPane().add( other, "South" ); this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); setVisible( true ); } // end RunInv } // end class RunInv extends JFrame implements ActionListener
-
First and foremost, I recommend that you learn the technique of incremental programming. This is where you add a little bit of code to your program, compile the new program, and then don't add any more code until you are sure that the code present is bug-free. Else you risk having a program with a gazillion errors such as we see above.
As for your first error, realize that whenever a class implements an interface such as the ActionListener interface, that class needs to implement all of the methods declared in the interface. ActionListener only declares one class, actionPerformed, and this class that implements the interface must therefore have this same method with the exact same method signature (i.e., public vs private vs protected, number and type of parameters,...) as defined in the interface. See the ActionListener API to know what the method signature should look like.Last edited by Fubarable; 08-09-2008 at 08:12 PM.
- 08-09-2008, 08:10 PM #3
You use the makeButton() method many times.
Where is it defined? The compiler can't find it, so it gives all those error messages.
To get rid of those error mesages create a method named: makeButton() with an argument of String and have it return a JButton.
Why do you have "implements ActionListener"? If you remove that, the error message will go away.JFrame implements ActionListener
- 08-09-2008, 08:38 PM #4
Member
- Join Date
- Jul 2008
- Posts
- 43
- Rep Power
- 0
Reply to Norm
Norm,
Thanks for the help with the ActionListener. I removed it from the program and it eliminated that error. I added the method for makeButton. That did not work as well for me. I am now getting the following errors. I highlighted in my code below what I added. Please advise me as to what I did wrong here. Thank you!
Errors
InventoryProgramPart5.java:266: illegal start of expression
public void setMakeButton( String JButton )
^
InventoryProgramPart5.java:266: illegal start of expression
public void setMakeButton( String JButton )
^
InventoryProgramPart5.java:266: ';' expected
public void setMakeButton( String JButton )
^
InventoryProgramPart5.java:266: ';' expected
public void setMakeButton( String JButton )
^
InventoryProgramPart5.java:272: illegal start of expression
public String getMakeButton()
^
InventoryProgramPart5.java:272: ';' expected
public String getMakeButton()
^
6 errors
Java Code:// CheckPoint: InventoryProgramPart5.java // Week 8 // This program calculates inventory value import java.util.Arrays; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class InventoryProgramPart5 { public static void main( String args[] ) { double restockingFee = 0.05; manufacturer[] inventory = new manufacturer[5]; // array of 5 inventory[0] = new manufacturer ( "notepads", restockingFee, "4000", "Ampad", 60, 2.75 ); inventory[1] = new manufacturer ( "pencils", restockingFee, "5000", "Bic", 75, 1.25 ); inventory[2] = new manufacturer ( "folders", restockingFee, "2000", "3M", 30, 4.75 ); inventory[3] = new manufacturer ( "envelopes", restockingFee, "1000", "Universal", 15, 5.25 ); inventory[4] = new manufacturer ( "markers", restockingFee, "3000", "Sanford", 45, 3.50 ); manufacturer temp[] = new manufacturer[1]; for( int j = 0; j < inventory.length - 1; j++ ) { for( int k = 0; k < inventory.length - 1; k++ ) { if( inventory[k].getItemName().compareToIgnoreCase ( inventory[k+1].getItemName() ) > 0 ) { temp[0] = inventory[k]; inventory[k] = inventory[k+1]; inventory[k+1] = temp[0]; } // end if } // end for } // end for javax.swing.JTextArea ta = new javax.swing.JTextArea( 10, 25 ); for( int j = 0; j < inventory.length; j++ ) { // System.out.println( inventory[j].toString() );<----------------- ta.append( inventory[j].toString()+"\n" ); } // end for // System.out.printf( "Total value of all inventory = $%.2f", // Inventory.etTotalValueOfAllInventory( inventory ) ); // return; // <------------------above line and this line ta.append("Total value of all inventory = "+product.getTotalValueOfAllInventory(inventory)); javax.swing.JFrame frame = new javax.swing.JFrame(); frame.getContentPane().add( new javax.swing.JScrollPane(ta) ); frame.pack(); frame.setLocationRelativeTo( null ); frame.setDefaultCloseOperation( javax.swing.JFrame.EXIT_ON_CLOSE ); frame.setVisible( true ); } // end main } // end class InventoryProgramPart5 // The product class class product { String productNumber; String name; int numberOfUnits; double pricePerUnit; // create a new instance of Inventory // main constructor for the class product( String Item_Number, String Item_Name, int Items_in_Stock, double Item_Price ) { productNumber = Item_Number; name = Item_Name; numberOfUnits = Items_in_Stock; pricePerUnit = Item_Price; } // end constructor // sets the product name public void setItemName( String Item_Name ) { name = Item_Name; } // sets the product number public void setItemNumber( String Item_Number ) { productNumber = Item_Number; } // sets the number of units in stock public void setItemsInStock( int Items_in_Stock ) { numberOfUnits = Items_in_Stock; } // sets the price of the product public void setItemPrice( double Item_Price ) { pricePerUnit = Item_Price; } // returns product name public String getItemName() { return name; } // returns product number public String getItemNumber() { return productNumber; } // returns units in stock public int getItemsInStock() { return numberOfUnits; } // returns product price public double getItemPrice() { return pricePerUnit; } // returns the total value of inventory public double getInventoryValue() { return pricePerUnit * numberOfUnits; } public static double getTotalValueOfAllInventory( product[] inv ) { double tot = 0.0; for( int i = 0; i < inv.length; i++ ) { tot += inv[i].getInventoryValue(); } return tot; } public String toString() { StringBuffer sb = new StringBuffer(); sb.append( "Product Name: \t" ).append( name ).append( "\n" ); sb.append( "Product Number: \t" ).append( productNumber ).append( "\n" ); sb.append( "Units in Stock: \t" ).append( numberOfUnits ).append( "\n" ); sb.append( "Unit Price: \t" ).append( String.format( "$%.2f%n", pricePerUnit ) ); sb.append( "Inventory Value: \t" ).append(String.format("$%.2f%n", this.getInventoryValue())); return sb.toString(); } // end toString } // end class product class manufacturer extends product { // manufacturer of product String manufacturer; // percentage added to base price as restocking fee double restockingFee; // actual inventory value will be the base inventory value plus // the base inventory value times this amount ( value + ( value * restockingFee ) ) public manufacturer( String Item_Name, double restockingFee, String Item_Number, String manufacturer, int Items_in_Stock, double Item_Price ) { super( Item_Number, Item_Name, Items_in_Stock, Item_Price); this.manufacturer = manufacturer; this.restockingFee = restockingFee; } // returns inventory value plus the restocking fee public double getInventoryValue() { return super.getInventoryValue() + ( super.getInventoryValue() * restockingFee ); } // end getInventoryValue public String toString() { StringBuffer sb = new StringBuffer( "Manufacturer: \t" ).append( manufacturer ).append( "\n" ); sb.append( super.toString() ); return sb.toString(); } // end toString } // end class manufacturer class RunInv extends JFrame // implements ActionListener { // utility class for displaying the picture private class MyPanel extends JPanel { ImageIcon image = new ImageIcon( "HTML.jpg" ); int width = image.getIconWidth(); int height = image.getIconHeight(); long angle = 0; public MyPanel() { super(); } public void paintComponent( Graphics g ) { super.paintComponent(g); Graphics2D g2d = ( Graphics2D )g; g2d.rotate( Math.toRadians(angle), 200+width/2, 90+height/2 ); g2d.drawImage( image.getImage(), 5, 5, this ); g2d.dispose(); } } // end class MyPanel int currentIndex; // currently displayed Item manufacturer[] inventory = new manufacturer[5]; JLabel name; JLabel number; JLabel manufacturer; JLabel units; JLabel price; JLabel fee; JLabel totalValue; JTextField nameField = new JTextField(20); JTextField numberField = new JTextField(20); JTextField manufacturerField = new JTextField(20); JTextField unitsField = new JTextField(20); JTextField priceField = new JTextField(20); JTextField totalValueField = new JTextField(20); JPanel display; JPanel displayHolder; JPanel panel; public RunInv() { makeTheDataItems(); setSize( 700, 300 ); setTitle( "Inventory Program" ); // make the panels display = new JPanel(); JPanel other = new JPanel(); JPanel picture = new MyPanel(); JPanel buttons = new JPanel(); JPanel centerPanel = new JPanel(); displayHolder = new JPanel(); display.setLayout( new GridLayout( 3, 3 ) ); other.setLayout( new GridLayout( 2, 1 ) ); // make the labels name = new JLabel( "Product Name:" ); number = new JLabel( "Product Number:" ); manufacturer = new JLabel( "Manufacturer:" ); units = new JLabel( "Units in Stock:" ); price = new JLabel( "Price :$" ); fee = new JLabel( "Fee :$" ); totalValue = new JLabel( "Total value : $" ); [B] // sets makeButton public void setMakeButton( String JButton ) { makeButton = JButton; } // method makeButton public String getMakeButton() { return JButton; }[/B] // make the buttons JButton first = makeButton( "First" ); JButton next = makeButton( "Next" ); JButton previous = makeButton( "Previous" ); JButton last = makeButton( "Last" ); JButton exit = makeButton( "Exit" ); // other buttons JButton add = makeButton( "Add" ); JButton delete = makeButton( "Delete" ); JButton modify = makeButton( "Modify" ); JButton save = makeButton( "Save" ); JButton find = makeButton( "Find" ); // add the labels to the display panel display.add( name ); display.add( number ); display.add( manufacturer ); display.add( units ); display.add( price ); display.add( fee ); display.add( totalValue ); // add the buttons to the buttonPanel buttons.add( first ); buttons.add( previous ); buttons.add( next ); buttons.add( last ); buttons.add( exit ); // add the picture panel and display to the centerPanel displayHolder.add( display ); centerPanel.setLayout( new GridLayout( 2, 1 ) ); centerPanel.add( picture ); centerPanel.add( displayHolder ); other.add( buttons ); JPanel forAdd = new JPanel(); // add the other buttons to this panel forAdd.add( find ); forAdd.add( add ); forAdd.add( modify ); forAdd.add( delete ); forAdd.add( save ); other.add( forAdd ); // add the panels to the frame getContentPane().add( centerPanel, "Center" ); getContentPane().add( other, "South" ); this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); setVisible( true ); } // end RunInv } // end class RunInv extends JFrame implements ActionListener
- 08-09-2008, 09:18 PM #5
Man you cannot declare the methods inside the constructor,declare them outside the constructer,and then call them in constructor as this.setMakeButton("makeButton");
The second thing in the method setMakeButton you have an error of missed signs,and the method should be :
public void setMakeButton(String button){
makeButton=new JButton(button);
}
The third thing each class create in another file.
The fourth thing,if you want to decrease the amount of lines,put the panels,buttons and other components to the arays and then pass over them with the for loop in order to add the components to the surface.You have much lines,and it is not comfortable.For example:
Jpanel p=new JPanel();
JButton[] buttons={new JButton("make button"),new JButton("Save"),...};
int i=0;
for(;i<buttons.length;i++){
p.add(buttons[i]);
buttons[i].addActionListener(this); //in condition if your class implements ActionListener
}
- 08-09-2008, 10:02 PM #6
Member
- Join Date
- Jul 2008
- Posts
- 43
- Rep Power
- 0
Reply to Serjant
Serjant,
I took your advice and separated my classes into separate files to make the code easier to manage. My InventoryProgramPart5, Product, and Manufacturer classes all work together. However, the RunInv class although I still have the makeButton errors to still figure out, I am getting errors on every line. In other words, 78 errors. What am I doing wrong? Do I need to add something to the main class located in the InventoryProgramPart5 file? Please advise. I will continue to work on figuring out the makeButton method. However, it will be easier if I can get the classes separated correctly. Thanks for your help!
- 08-09-2008, 10:46 PM #7
Member
- Join Date
- Jul 2008
- Posts
- 43
- Rep Power
- 0
Reply to Serjant
Serjant,
I still can't seem to get the makeButton method to work. I don't know if I have written it correctly or put it in the right spot. Excuse my ignorance when it comes to Java. I have a teacher that expects us to learn it all on our own. Therefore, the only things I know about Java is what I have learned on the Web site. I sort of know what a constructor is but I don't know what the constructor is in my RunInv class. Therefore, I am having trouble creating the method for the makeButton. Please help me figure this out. For reference, I have posted only the RunInv class below since I have not made any changes to the other classes of the code I posted earlier. Thank you!
Java Code:class RunInv extends JFrame // implements ActionListener { // utility class for displaying the picture private class MyPanel extends JPanel { ImageIcon image = new ImageIcon( "HTML.jpg" ); int width = image.getIconWidth(); int height = image.getIconHeight(); long angle = 0; public MyPanel() { super(); } public void paintComponent( Graphics g ) { super.paintComponent(g); Graphics2D g2d = ( Graphics2D )g; g2d.rotate( Math.toRadians(angle), 200+width/2, 90+height/2 ); g2d.drawImage( image.getImage(), 5, 5, this ); g2d.dispose(); } } // end class MyPanel int currentIndex; // currently displayed Item manufacturer[] inventory = new manufacturer[5]; JLabel name; JLabel number; JLabel manufacturer; JLabel units; JLabel price; JLabel fee; JLabel totalValue; JTextField nameField = new JTextField(20); JTextField numberField = new JTextField(20); JTextField manufacturerField = new JTextField(20); JTextField unitsField = new JTextField(20); JTextField priceField = new JTextField(20); JTextField totalValueField = new JTextField(20); JPanel display; JPanel displayHolder; JPanel panel; public void setMakeButton( String button ) { button = new JButton( button ); } public RunInv() { makeTheDataItems(); setSize( 700, 300 ); setTitle( "Inventory Program" ); // make the panels display = new JPanel(); JPanel other = new JPanel(); JPanel picture = new MyPanel(); JPanel buttons = new JPanel(); JPanel centerPanel = new JPanel(); displayHolder = new JPanel(); display.setLayout( new GridLayout( 3, 3 ) ); other.setLayout( new GridLayout( 2, 1 ) ); // make the labels name = new JLabel( "Product Name:" ); number = new JLabel( "Product Number:" ); manufacturer = new JLabel( "Manufacturer:" ); units = new JLabel( "Units in Stock:" ); price = new JLabel( "Price :$" ); fee = new JLabel( "Fee :$" ); totalValue = new JLabel( "Total value : $" ); // make the buttons JButton first = makeButton( "First" ); JButton next = makeButton( "Next" ); JButton previous = makeButton( "Previous" ); JButton last = makeButton( "Last" ); JButton exit = makeButton( "Exit" ); // other buttons JButton add = makeButton( "Add" ); JButton delete = makeButton( "Delete" ); JButton modify = makeButton( "Modify" ); JButton save = makeButton( "Save" ); JButton find = makeButton( "Find" ); // add the labels to the display panel display.add( name ); display.add( number ); display.add( manufacturer ); display.add( units ); display.add( price ); display.add( fee ); display.add( totalValue ); // add the buttons to the buttonPanel buttons.add( first ); buttons.add( previous ); buttons.add( next ); buttons.add( last ); buttons.add( exit ); // add the picture panel and display to the centerPanel displayHolder.add( display ); centerPanel.setLayout( new GridLayout( 2, 1 ) ); centerPanel.add( picture ); centerPanel.add( displayHolder ); other.add( buttons ); JPanel forAdd = new JPanel(); // add the other buttons to this panel forAdd.add( find ); forAdd.add( add ); forAdd.add( modify ); forAdd.add( delete ); forAdd.add( save ); other.add( forAdd ); // add the panels to the frame getContentPane().add( centerPanel, "Center" ); getContentPane().add( other, "South" ); this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); setVisible( true ); } // end RunInv } // end class RunInv extends JFrame implements ActionListener
-
I think that your best bet here is to have a face-to-face sit down conference with your instructor or with a tutor. Our handing out tidbits are not going to help you learn the so many concepts that you need. Much luck.
- 08-09-2008, 11:04 PM #9
Member
- Join Date
- Jul 2008
- Posts
- 43
- Rep Power
- 0
I have already tried that. I am an online student and have no one to ask other than those on the Internet. My assignment is due on tomorrow, August 10. If you could point me in the right direction, I would appreciate it.
- 08-09-2008, 11:15 PM #10
Knowing how to write a constructor is VERY basic(and important) to writing java classes.don't know what the constructor is in my RunInv class
You have to go back and read your text on how to do that.
Next knowing how to write a method is just as important. In fact a Constructor is a special kind of method and is coded a lot like a method.
Before trying to write code, read your text about these.
Try writing a small simple program to use these two techniques:
The Constructor to the class will take one int as arg.
It will have one method that has an int as arg, adds that int to the one passed in the constructor and returns the sum.
The main method will create an instance of that class passing an int value in its constructor and then will call the method with another int and print the results returned by the method.Last edited by Norm; 08-09-2008 at 11:30 PM.
-
From your other posts I have to conclude that you don't yet have the basic concepts needed to complete this assignment, and those concepts are key. Our handing you a solution will not help you gain these concepts and in fact will only short change you, your education, and your institution. The bottom line is that you still need to make the effort to learn these, but unfortunately the last minute may not give you time enough to do this. My recommendation is still that you arrange a tutoring session either online with your instructor with face to face with someone local. This really offers you your best bet. You may be able to ask for an extension, and you may not, but also please realize that your urgency is not ours, a sad but true fact. Again, best of luck.
edit: on looking through your last post, I don't see that you have a method there called makeButton(). You call it, but do you define it?Last edited by Fubarable; 08-09-2008 at 11:34 PM.
- 08-10-2008, 12:04 AM #12
Member
- Join Date
- Jul 2008
- Posts
- 43
- Rep Power
- 0
Is this a good example of a constructor and method? The only thing I cannot find in the textbook is where to place this in the code. For example, does it get placed at the beginning of the class?
private String makeButton;
// constructor initializes makeButton
public makeButton( String button)
{
button = new JButton( button ); // initializes button
} // end constructor
// method to set makeButton
public void setMakeButton( String button)
{
button = new JButton; // store the button
} // end setMakeButton
// method to retrieve makeButton
public String getMakeButton()
{
return makeButton();
} // end method getMakeButton
- 08-10-2008, 01:10 AM #13
The first statement defines a String variable named makeButton.private String makeButton;
// constructor initializes makeButton
public makeButton( String button)
The second statement is a constructor for the class makeButton.
To use the same name for a variable and for a class that are completely different is very poor technique.
There are too many poor techniques in what you just posted to bother with. You need to start simple and expand from there.
Did you try writing a simple program as I suggested?
Similar Threads
-
Java Errors! Please help!
By TearsOfTheMoon in forum New To JavaReplies: 2Last Post: 06-10-2008, 09:00 AM -
help with these errors
By oceansdepth in forum New To JavaReplies: 3Last Post: 04-16-2008, 04:55 PM -
Errors I don't understand
By MattyB in forum New To JavaReplies: 4Last Post: 04-01-2008, 11:55 PM -
I have 3 errors after compiling
By coco in forum JDBCReplies: 2Last Post: 10-18-2007, 09:32 AM -
Errors in constructor
By ai_2007 in forum Advanced JavaReplies: 0Last Post: 07-01-2007, 05:35 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks