Reputation: 11
public class code extends JFrame{
/**
*
*/
private static final long serialVersionUID = 1L;
public boolean flag = true;
JButton Bill;
JButton Enter;
JTextField Items;
JTextField Amount;
public java.util.List<String> Item_list = new ArrayList<String>();
public java.util.List<String> quantity = new ArrayList<String>();
public code() {
super("Market");
setLayout(new FlowLayout());
do {
Items = new JTextField("Enter the Item u wish to purchase");
add(Items);
Items.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
command(e.getActionCommand());
}
}
);
Amount = new JTextField("Enter the quantity of the product");
add(Amount);
Amount.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
commandInt(e.getActionCommand());
}
}
);
Bill = new JButton();
add(Bill);
Bill.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
flag = false;
}
}
);
} while(flag);
}
public void command(String userT) {
try {
Item_list.add(userT);
} catch(Exception e){
System.out.println("what was that");
}
}
public void commandInt(String string) {
try {
quantity.add(string);
} catch(Exception e) {
System.out.println("what was that");
}
}
}
This code is basically just a system where u input the item and the amount and it stores it in a list but something is obviously wrong because it doesn't compile. Further when it does compile they highlighted region JTextField
area. there seems to be no apparent problem.
Upvotes: 0
Views: 58
Reputation: 34176
Try importing the classes you are using:
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
Upvotes: 0
Reputation: 111
As you didn't specify the error or warning I'll give a general answer.
If you hover over the words that are underlined then they will give you a brief description of the problem.
In eclipse you can use the shortcut alt + enter to get suggestions on how to solve the problem.
If the problem is an error then it will be highlighted red. Else, if it is a warning then it will be underlined yellow.
An error is a fault in the code you wrote where a warning is more of a suggestion from a good friend telling you to fix something.
Upvotes: 1