This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Causes of 'java.lang.NoSuchMethodError: main Exception in thread “main”'
I'm getting the following error:
java.lang.NoSuchMethodError: main
Exception in thread "main"
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
public class SwimCalc extends JFrame implements ActionListener {
private JTabbedPane jtabbedPane;
private JPanel Customers;
JTextArea NameTextCustomers, ExistTextCustomers, NameTextContractors,
ExistTextContractors;
public SwimCalc() {
setTitle("Volume Calculator");
setSize(300, 200);
JPanel topPanel = new JPanel();
topPanel.setLayout(new BorderLayout());
getContentPane().add(topPanel);
createCustomers();
jtabbedPane = new JTabbedPane();
jtabbedPane.addTab("Customers", Customers);
topPanel.add(jtabbedPane, BorderLayout.CENTER);
}
/* CREATE CUSTOMERS */
public JPanel createCustomers() {
Customers = new JPanel();
Customers.setLayout(null);
NameTextCustomers = new JTextArea();
NameTextCustomers.setBounds(10, 10, 350, 150);
NameTextCustomers.setLineWrap(true);
Customers.add(NameTextCustomers);
JButton Exit = new JButton("Exit");
Exit.setBounds(30, 170, 80, 20);
Exit.addActionListener(this);
Exit.setBackground(Color.white);
Customers.add(Exit);
JButton AddCustomers = new JButton("Add Customer");
AddCustomers.setBounds(130, 170, 120, 20);
AddCustomers.setBackground(Color.white);
Customers.add(AddCustomers);
JButton Refresh = new JButton("Refresh");
Refresh.setBounds(260, 170, 80, 20);
Refresh.setBackground(Color.white);
Customers.add(Refresh);
ExistTextCustomers = new JTextArea();
ExistTextCustomers.setBounds(10, 200, 350, 60);
ExistTextCustomers.setLineWrap(true);
Customers.add(ExistTextCustomers);
final JTextArea custArea = new JTextArea(6, 30);
final JTextArea custMessage = null;
AddCustomers.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new Customer("Customer");
}
});
Customers.add(custArea);
Customers.add(AddCustomers);
Customers.add(Refresh);
Customers.add(custMessage);
Refresh.setMnemonic('R');
Refresh.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
custMessage.setText("");
try {
File custOpen = new File("customer.txt");
FileReader custAreaIn = new FileReader(custOpen);
custArea.read(custAreaIn, custOpen.toString());
custMessage.setText("The file exists and can be read from.");
} catch (IOException e3) {
custMessage.setText("The file could not be read. "
+ e3.getMessage());
}
}
});
return Customers;
}
class Customer extends JFrame {
private String[] states = { "AL", "AK", "AZ", "AR", "CA", "CO", "CT",
"DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA",
"ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH",
"NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC",
"SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY" };
private JComboBox StateList = new JComboBox(states);
private JTextField NameText = new JTextField(25);
private JTextField AddressText = new JTextField(25);
private JTextField CityText = new JTextField(25);
private JTextField ZipText = new JTextField(9);
private JTextField PhoneText = new JTextField(10);
private JTextField PopMessageText = new JTextField(30);
private static final long serialVersionUID = 1L;
private AddCustButtonHandler addCusHandler = new AddCustButtonHandler();
public Customer(String who) {
popUpWindow(who);
}
public void popUpWindow(final String who) {
final JFrame popWindow;
popWindow = new JFrame(who);
popWindow.setSize(425, 350);
popWindow.setLocation(100, 100);
popWindow.setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container c = new Container();
popWindow.add(c);
c.setLayout(new FlowLayout());
JPanel one = new JPanel();
JPanel two = new JPanel();
JPanel three = new JPanel();
JPanel four = new JPanel();
JPanel five = new JPanel();
JPanel six = new JPanel();
one.add(new JLabel(who + " Name "));
one.add(NameText);
two.add(new JLabel("Address "));
two.add(AddressText);
three.add(new JLabel("City "));
three.add(CityText);
four.add(new JLabel("State "));
StateList.setSelectedIndex(0);
four.add(StateList);
four.add(new JLabel("ZIP"));
four.add(ZipText);
four.add(new JLabel("Phone"));
four.add(PhoneText);
JButton addwho = new JButton("Add " + who);
addwho.setMnemonic('A');
JButton close = new JButton("Close");
close.setMnemonic('C');
JButton deleteFile = new JButton("Delete File");
deleteFile.setMnemonic('D');
five.add(addwho);
five.add(close);
five.add(deleteFile);
PopMessageText.setEditable(false);
PopMessageText.setHorizontalAlignment(JTextField.CENTER);
six.add(PopMessageText);
c.add(one);
c.add(two);
c.add(three);
c.add(four);
c.add(five);
c.add(six);
deleteFile.setToolTipText("Delete File");
addwho.setToolTipText("Add " + who);
close.setToolTipText("Close");
if (who == "Customer")
addwho.addActionListener(addCusHandler);
close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
NameText.setText("");
AddressText.setText("");
CityText.setText("");
ZipText.setText("");
PhoneText.setText("");
PopMessageText.setText("");
popWindow.dispose();
}
});
deleteFile.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PopMessageText.setText("");
if (who == "Customer") {
File file = new File("Customer.txt");
boolean cusFileDeleted = file.delete();
if (cusFileDeleted) {
PopMessageText.setText("Customer file has been deleted");
} else {
PopMessageText
.setText("There was an erron in deleting file");
}
}
}
});
}
class AddCustButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent addCusHandler) {
int StateIndex;
try {
File file = new File("Customer.txt");
boolean success = file.createNewFile();
if (success) {
PopMessageText
.setText("Customer.txt file created file added");
} else if (file.canWrite()) {
PopMessageText
.setText("Writing data to Customer.txt, file added");
} else {
PopMessageText.setText("Cannot create file: Customer.txt");
}
try {
FileWriter fileW = new FileWriter("Customer.txt", true);
fileW.write(NameText.getText());
fileW.write(",");
fileW.write(AddressText.getText());
fileW.write(",");
fileW.write(CityText.getText());
fileW.write(",");
StateIndex = StateList.getSelectedIndex();
fileW.write(states[StateIndex]);
fileW.write(",");
fileW.write(ZipText.getText());
fileW.write(",");
fileW.write(PhoneText.getText());
fileW.write("\r\n");
fileW.close();
PopMessageText.setText("A new Customer has been added!");
FileReader fileR = new FileReader("Customer.txt");
BufferedReader buffIn = new BufferedReader(fileR);
String textData = buffIn.readLine();
buffIn.close();
} catch (IOException e1) {
JOptionPane.showMessageDialog(null, e1.getMessage(), "ERROR",
2);
}
NameText.setText("");
AddressText.setText("");
CityText.setText("");
ZipText.setText("");
PhoneText.setText("");
} catch (IOException e1) {
}
}
}
public void actionPerformed(ActionEvent event) {
}
private void Exit_pressed() {
System.exit(0);
}
public void main(String[] args) {
JFrame frame = new SwimCalc();
frame.setSize(380, 350);
frame.setVisible(true);
}
}
public void actionPerformed(ActionEvent e) {
}
}
The error:
java.lang.NoSuchMethodError: main
Exception in thread "main"
public void actionPerformed(ActionEvent e) {
}
public static void main(String[] args){
JFrame frame = new SwimCalc();
frame.setSize(380, 350);
frame.setVisible(true);
}
}
main needs to be a static method.
public static void main(String[] args){
JFrame frame = new SwimCalc();
frame.setSize(380, 350);
frame.setVisible(true);
}
Also, the main method should be in the SwimCalc class or some other top-level class. Move the method to be within the SwimCalc class (not in your Customer class) and use java SwimCalc to invoke it. You can't declare main in an inner class.
It looks your main method is actually inside your actionPerformed method. You obviously cannot do this. The declaration needs to be in your SwimCalc class. Is that craziness your actual code that you are trying to run? You've got braces and stray parentheses all over the place, no indentation; if you just clean up your code the problem will be a lot easier to find.
and
public void main(String[] args){
should be
public static void main(String[] args){
There's also nonsense like this: } );. You have so many syntax errors...
Yes the signature should be
public static void main(String[] args)
Even if the args is missed eclipse throws this error.
public **static** void main(String[] args){
Main method must be public static
public static void main(String[] args)
main() must be static. The complete signature is:
public static void main(String[] args)
You main method needs to be static. This should be the signature:
public static void main(String[] args)
It should be
public static void main(String[] args){
instead of public void main...
Related
I have application where on Jbutton click i create new JFrame with its own class and import file
When i read file i passed that file to method of my MainGui class where i parse data and store it in array of objects which is global field.
When i click on another button from MainGui, i cant access that array of objets and none of its fields(i get nullPointerException)
Here is my code:
MainGui Class
public class MainGui implements ActionListener {
private JFrame frame;
private JPanel panel;
GrupaArtikala[] objektiArtikli; // ARRAY OF OBJECTS
JPanel centerPanel = new JPanel(new BorderLayout());
private final int MAX_TABLES = 8;
JButton buttonImport;
JButton [] buttonsTables = new JButton[MAX_TABLES];
String tables[] = {
"Grupa artikala",
"Osnovna mera",
"Jedinica mere",
"Naknada",
"Popust",
"Artikal",
"Normativ",
"Normativ stavka",
};
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainGui window = new MainGui();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
private void createAndShowPodesavanja() {
GuiFileChooser guiPodesavanja= new GuiFileChooser(); // HERE I CREATE NEW FRAME
guiPodesavanja.initialize();
guiPodesavanja.setVisible(true);
// this.setVisible(false);
}
public MainGui() {
initialize();
}
public void pars(String file) {
try {
String content = new String(Files.readAllBytes(Paths.get(file)));
int startArtikitag = content.indexOf(":ISSI");
int endArticalTag = content.indexOf("#TABLENAME:OSNOVNA_MJERA");
String gupaArtikalaString = content.substring(startArtikitag + 5, endArticalTag - 15);
System.out.println(gupaArtikalaString);
String[] lines =gupaArtikalaString.split(System.lineSeparator());
objektiArtikli = new GrupaArtikala[lines.length];
for(int i = 1; i < lines.length; i++) {
objektiArtikli[i] = new GrupaArtikala(lines[i]); // HERE I INITALIAZE ARRAY OF OBJECTS
}
System.out.println("rec u konstruktoru lokalno " + objektiArtikli[1].getId());
System.out.println("rec u gobalno" + objektiArtikli[1].getId());
// HERE I HAVE OUTPUT
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
initialize();
}
private void initialize() {
frame = new JFrame("FreshPos baza podataka");
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
// Main paneel
panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setBorder( BorderFactory.createEmptyBorder(10,10,10,10) );
frame.getContentPane().add(panel);
//West panel;
JPanel panelWest = new JPanel(new GridLayout(14,0,0,2));
panelWest.setBorder( BorderFactory.createEmptyBorder(200,0,10,10) );
panel.add(panelWest, BorderLayout.WEST);
for (int i = 0; i < MAX_TABLES; i++) {
buttonsTables[i] = new JButton(tables[i]);
//buttonsTables[i].setMaximumSize(new Dimension(Integer.MAX_VALUE, buttonsTables[i].getMinimumSize().height));
//buttonsTables[i].setPreferredSize(new Dimension(200,400));
panelWest.add(buttonsTables[i]);
}
buttonsTables[0].addActionListener(this); // HERE I CLICK ON BUTTON!!
//North panel;
JPanel northPanel = new JPanel(); // Donji layout za dugmice
northPanel.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
panel.add(northPanel, BorderLayout.NORTH);
//northPanel.setBackground(Color.green);
buttonImport = new JButton("Importuj datoteku");
buttonImport.setPreferredSize(new Dimension(180,40));
northPanel.add(buttonImport, BorderLayout.WEST);
buttonImport.addActionListener(this);
JButton ButtonRecord = new JButton("Snimi datoteku");
ButtonRecord.setPreferredSize(new Dimension(180,40));
northPanel.add(ButtonRecord, BorderLayout.WEST);
}
public void showGrupaArtikala () {
centerPanel.removeAll();
centerPanel.updateUI();
centerPanel.setBackground(Color.GRAY);
panel.add(centerPanel, BorderLayout.CENTER);
JPanel southInCentral = new JPanel(); // Donji layout za dugmice
centerPanel.add(southInCentral, BorderLayout.SOUTH);
JButton buttonDodaj = new JButton("Dodaj");
//buttonDodaj.setLocation(100, 100);
buttonDodaj.setPreferredSize(new Dimension(180,40));
southInCentral.add(buttonDodaj);
JButton buttonIzmeni = new JButton("Izmeni");
buttonIzmeni.setPreferredSize(new Dimension(180,40));
southInCentral.add(buttonIzmeni);
JButton butonObrisi = new JButton("Obrisi");
butonObrisi.setPreferredSize(new Dimension(180,40));
southInCentral.add(butonObrisi);
// Center layout in central panel
JPanel centralInCentral = new JPanel(); //
centerPanel.add(centralInCentral);
// Jtable
String[] columnNames = {"ID,",
"SIFRA",
"NAZIV",
"IKONA_ID"};
Object[][] data = {
{"Kathy", "Smith", "Snowboarding", new Integer(5), new Boolean(false)},
{"John", "Doe", "Rowing", new Integer(3), new Boolean(true)},
{"Sue", "Black", "Knitting", new Integer(2), new Boolean(false)},
{"Jane", "White", "Speed reading", new Integer(20), new Boolean(true)},
{"Joe", "Brown", "Pool", new Integer(10), new Boolean(false)}
};
JTable table = new JTable(data, columnNames);
//JTable(Object[][] rowData, Object[] columnNames)
JScrollPane scrollPane = new JScrollPane(table);
centerPanel.add(scrollPane);
panel.repaint();
panel.revalidate();
#Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == buttonsTables[0]) {
System.out.println("String here "+ objektiArtikli[1].getId()); // HERE OUTPUT IS NULL
showGrupaArtikala();
} else if (e.getSource() == buttonImport) {
System.out.println("aa");
createAndShowPodesavanja();
}
}
}
GuiFileChooser Class
public class GuiFileChooser {
private JFrame frame;
JTextField jEditText;
public GuiFileChooser () {
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
GuiFileChooser window = new GuiFileChooser();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
private void fileChoose(ActionEvent evt) {
JFileChooser chooser = new JFileChooser();
int i=chooser.showOpenDialog(frame);
if(i==JFileChooser.APPROVE_OPTION){
File f = chooser.getSelectedFile();
String filename = f.getAbsolutePath();
MainGui m = new MainGui();
m.pars(filename); // HERE I CALL pars(filename) in MainGui method
jEditText.setText(filename);
}
}
void initialize() {
frame = new JFrame();
frame.setTitle("Dodaj datoteku");
frame.setBounds(750, 350, 460, 150); // top
//Dimension d = new Dimension(440, 200);
// Dimension d1 = new Dimension(451, 451);
frame.setResizable(false);
//frame.setPreferredSize(d);
//frame.setMinimumSize(d);
// frame.setMaximumSize(d1);
// frame.setSize(450, 450);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().setLayout(null);
JButton lblNaziv = new JButton("Izaberite datoteku..");
lblNaziv.setBounds(10 ,10, 160, 25); // horizontalna margina , vertikalna margina , visina, duzina
lblNaziv.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
fileChoose(evt);
}
});
frame.getContentPane().add(lblNaziv);
jEditText = new JTextField();
jEditText.setBounds(180 ,10, 250, 25); // horizontalna margina , vertikalna margina , visina, duzina
frame.getContentPane().add(jEditText);
JButton buttonOk = new JButton("OK");
buttonOk.setBounds(180,50, 100, 30); // horizontalna margina , vertikalna margina ,
frame.getContentPane().add(buttonOk);
buttonOk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
frame.dispose();
}
});
}
public void setVisible(boolean b) {
frame.setVisible(b);
}
}
I want to assign dir array to comboBox. Is there any error in my code. I tried to display the dir array it contains the values but cannot assign it comboBox. Here is the code.
import java.awt.EventQueue;
public class ExpenseManager {
private JFrame frame;
private JTextField txtUserName;
private JLabel lblNewUserName;
private JButton btnDone;
private JButton btnLogin;
private JComboBox<?> comboBox;
private String[] dir = new String[100];
private String[] hello = {"Hii", "Hello"};
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ExpenseManager window = new ExpenseManager();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public ExpenseManager() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
//#SuppressWarnings("unchecked")
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JButton btnNewUser = new JButton("New User");
btnNewUser.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
lblNewUserName.setVisible(true);
txtUserName.setVisible(true);
btnDone.setVisible(true);
}
});
btnNewUser.setBounds(23, 34, 89, 23);
frame.getContentPane().add(btnNewUser);
txtUserName = new JTextField();
txtUserName.setBounds(240, 63, 134, 20);
frame.getContentPane().add(txtUserName);
txtUserName.setVisible(false);
txtUserName.setColumns(10);
lblNewUserName = new JLabel("Enter New UserName");
lblNewUserName.setBounds(240, 38, 134, 14);
lblNewUserName.setVisible(false);
frame.getContentPane().add(lblNewUserName);
btnDone = new JButton("Done");
btnDone.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String newUserName = txtUserName.getText();
if(!newUserName.isEmpty())
{
File f = new File("S:/Expense/" + newUserName);
if (f.exists() && f.isDirectory()) {
JOptionPane.showMessageDialog(null, "User already exists");
txtUserName.setText(null);
}
else{
boolean success = (new File("S:/Expense/" + newUserName)).mkdir();
if(!success){
JOptionPane.showMessageDialog(null, "Unable to register");
}else{
JOptionPane.showMessageDialog(null, "User registered Successfully");
}
}
}
else
{
JOptionPane.showMessageDialog(null, "Kindly enter User Name", "Invalid User Name", JOptionPane.ERROR_MESSAGE);
}
}
});
btnDone.setBounds(240, 103, 89, 23);
btnDone.setVisible(false);
frame.getContentPane().add(btnDone);
btnLogin = new JButton("Login");
btnLogin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
File[] directories = new File("S:/Expense/").listFiles();
for(int i = 0; i < directories.length; i++)
{
dir[i] = directories[i].getName();
}
comboBox.setVisible(true);
}
});
btnLogin.setBounds(23, 68, 89, 23);
frame.getContentPane().add(btnLogin);
comboBox = new JComboBox<Object>(dir);
comboBox.setBounds(24, 138, 72, 20);
comboBox.setSelectedIndex(1);
comboBox.setVisible(false);
frame.getContentPane().add(comboBox);
}
}
You can use setModel with DefaultComboBoxModel which take an array instead like :
comboBox.setModel(new DefaultComboBoxModel(dir));
Most of the code posted is not relevant to the question asked, so it should be removed (see MCVE).
Review the following, note the comments:
public class ExpenseManager {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
#Override
public void run() {
try {
new ExpenseManager();
} catch (Exception e) { e.printStackTrace(); }
}
});
}
public ExpenseManager() { initialize(); }
private void initialize() {
JFrame frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null); //better use a layout manger
JComboBox<String> comboBox = new JComboBox<>();
comboBox.setBounds(24, 138, 72, 20);
comboBox.setVisible(false);
frame.getContentPane().add(comboBox);
JButton btn = new JButton("Populate combo");
btn.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent arg0) {
//populate combo
String[] dir = new String[5];
for(int i = 0; i < dir.length; i++) { dir[i] = "String "+ i;}
comboBox.setModel(new DefaultComboBoxModel<>(dir));
comboBox.setVisible(true);
btn.setEnabled(false); //disable button
}
});
btn.setBounds(23, 68, 89, 23);
frame.getContentPane().add(btn);
frame.setVisible(true);
}
}
EDIT implementation using a layout manager :
private void initialize() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JComboBox<String> comboBox = new JComboBox<>();
comboBox.setVisible(false);
frame.add(comboBox, BorderLayout.SOUTH); //using BorderLayout which is the default
JButton btn = new JButton("Populate combo");
btn.setPreferredSize(new Dimension(150,35));
btn.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent arg0) {
//populate combo
String[] dir = new String[5];
for(int i = 0; i < dir.length; i++) { dir[i] = "String "+ i;}
comboBox.setModel(new DefaultComboBoxModel<>(dir));
comboBox.setVisible(true);
btn.setEnabled(false); //disable button
frame.pack(); //resize fram to fit the preferred size and layouts
}
});
frame.getContentPane().add(btn, BorderLayout.NORTH);
frame.pack();
frame.setVisible(true);
}
so I am trying to have my program read a list of lines from a txt file. This is then displayed in a JTextArea. The user can input data using the JTextField and the goal is to display "Hooray" if the user matches the text in the JArea and "Wrong!" if they do not. Any help is appreciated.
public class TextArea1 {
JTextArea text;
JFrame frame;
JTextField textField;
public int k;
public ArrayList aList;
public String correctAnswer;
public static void main(String[] args) {
TextArea1 gui = new TextArea1();
gui.go();
}
private String textLine;
public void go() {
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
textField = new JTextField("");
textField.addActionListener(new startTextFieldListener("correct answer"));
JButton startButton = new JButton("Start!");
startButton.addActionListener(new startButtonListener(aList));
text = new JTextArea(30, 60);
text.setLineWrap(true);
JScrollPane scroller = new JScrollPane(text);
scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
panel.add(scroller);
frame.getContentPane().add(BorderLayout.CENTER, panel);
frame.getContentPane().add(BorderLayout.WEST, startButton);
frame.getContentPane().add(BorderLayout.SOUTH, textField);
frame.setSize(350, 300);
frame.setVisible(true);
}
class startButtonListener implements ActionListener {
ArrayList aList;
startButtonListener(ArrayList passedInList) {
aList = passedInList;
}
#Override
public void actionPerformed(ActionEvent event) {
String fileName = "test.txt";
String line;
ArrayList aList = new ArrayList();
try {
try (BufferedReader input = new BufferedReader(new FileReader(fileName))) {
if (!input.ready()) {
throw new IOException();
}
while ((line = input.readLine()) != null) {
aList.add(line);
}
}
} catch (IOException e) {
System.out.println(e);
}
int sz = aList.size();
for (int k = 0; k < sz; k++) {
String correctAnswer = aList.get(k).toString();
text.append(aList.get(k).toString());
text.append("\n");
}
}
}
class startTextFieldListener implements ActionListener {
String correctAnswer;
startTextFieldListener(String answer) {
correctAnswer = answer;
}
#Override
public void actionPerformed(ActionEvent event) {
if (text.getText().equals(correctAnswer)) {
JOptionPane.showMessageDialog(null, "Hooray!");
} else {
JOptionPane.showMessageDialog(null, "Wrong!");
}
}
}
}
Ok Try this one:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
public class TextArea1{
JTextArea text;
JFrame frame;
JTextField textField;
public int k;
public ArrayList aList;
public String correctAnswer;
public static void main (String [] args) {
TextArea1 gui = new TextArea1();
gui.go();
}
private String textLine;
public void go() {
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
textField = new JTextField("");
JButton startButton = new JButton ("Start!");
startButton.addActionListener(new startButtonListener());
text = new JTextArea (30, 60);
text.setLineWrap(true);
JScrollPane scroller = new JScrollPane(text);
scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
panel.add(scroller);
frame.getContentPane().add(BorderLayout.CENTER, panel);
frame.getContentPane().add(BorderLayout.WEST, startButton);
frame.getContentPane().add(BorderLayout.SOUTH, textField);
frame.setSize(350, 300);
frame.setVisible(true);
}
class startButtonListener implements ActionListener {
ArrayList aList;
public void actionPerformed(ActionEvent event) {
String fileName = "test.txt";
String line;
ArrayList <String>aList = new ArrayList<>();
try {
try (BufferedReader input = new BufferedReader (new FileReader(fileName))) {
if (!input.ready()) {
throw new IOException();
}
while ((line = input.readLine()) !=null) {
aList.add(line);
}
}
} catch (IOException e) {
System.out.println(e);
}
int sz = aList.size();
boolean result=false;
for(String t:aList){
if (t.equalsIgnoreCase(textField.getText())) {
JOptionPane.showMessageDialog(null, "Hooray! Loading File contents....");
int count=0;
for (int k = 0; k< sz; k++) {
text.append(aList.get(k).toString());
System.out.println(count);
count++;
// if(k<sz-1)
// text.append(", ");
text.append("\n");
}
result=true;
break;
}
else {
result=false;
}
}
if(!result){
JOptionPane.showMessageDialog(null, "Wrong!");
}
}
}
}
In this it will look for you text enter in textfield and if it matches it will add entire file content line by line. i have already tested. But remember i am not having sufficient time so ,i have not done regex pattern matching it is simple equal comparison with one line in you text file with text entered in textbox exactly.
Well, I have just modified your code so that you will get proper message when value in contain in list. look and modify accordingly.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
public class TextArea1{
JTextArea text;
JFrame frame;
JTextField textField;
public int k;
public String correctAnswer;
public static void main (String [] args) {
TextArea1 gui = new TextArea1();
gui.go();
}
private String textLine;
public void go() {
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
textField = new JTextField("");
//textField.addActionListener(new startTextFieldListener("correct answer"));
JButton startButton = new JButton ("Start!");
startButton.addActionListener(new startButtonListener());
text = new JTextArea (30, 60);
text.setLineWrap(true);
JScrollPane scroller = new JScrollPane(text);
scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
panel.add(scroller);
frame.getContentPane().add(BorderLayout.CENTER, panel);
frame.getContentPane().add(BorderLayout.WEST, startButton);
frame.getContentPane().add(BorderLayout.SOUTH, textField);
frame.setSize(350, 300);
frame.setVisible(true);
}
class startButtonListener implements ActionListener {
ArrayList aList;
startButtonListener()
{
}
public void actionPerformed(ActionEvent event) {
String fileName = "test.txt";
String line;
ArrayList aList = new ArrayList();
try {
try (BufferedReader input = new BufferedReader (new FileReader(fileName))) {
if (!input.ready()) {
throw new IOException();
}
while ((line = input.readLine()) !=null) {
aList.add(line);
}
System.out.println("List ready to check. values in list are :"+aList);
}
} catch (IOException e) {
System.out.println(e);
}
if (aList.contains(text.getText())) {
JOptionPane.showMessageDialog(null, "Hooray!");
}
else {
JOptionPane.showMessageDialog(null, "Wrong!");
}
}
}
}
if this is correct then mark it as correct.
Minor mistake you added a new line each time you append to the textArea.. that why its not comparing due to the extra new line
if you have new line in you file no problem the arrayList has it already when you parse the file so no need to add new line.
solution:
public class TextArea1{
JTextArea text;
JFrame frame;
JTextField textField;
public int k;
public String correctAnswer;
public static void main (String [] args) {
TextArea1 gui = new TextArea1();
gui.go();
}
private String textLine;
public void go() {
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
textField = new JTextField("");
//textField.addActionListener(new startTextFieldListener("correct answer"));
JButton startButton = new JButton ("Start!");
startButton.addActionListener(new startButtonListener());
text = new JTextArea (30, 60);
text.setLineWrap(true);
JScrollPane scroller = new JScrollPane(text);
scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
panel.add(scroller);
frame.getContentPane().add(BorderLayout.CENTER, panel);
frame.getContentPane().add(BorderLayout.WEST, startButton);
frame.getContentPane().add(BorderLayout.SOUTH, textField);
frame.setSize(350, 300);
frame.setVisible(true);
}
class startButtonListener implements ActionListener {
ArrayList aList;
startButtonListener()
{
}
public void actionPerformed(ActionEvent event) {
String fileName = "test.txt";
String line;
String string = "";
try {
try (BufferedReader input = new BufferedReader (new FileReader(fileName))) {
if (!input.ready()) {
throw new IOException();
}
while ((line = input.readLine()) !=null) {
string += line;
//aList.add(line);
}
System.out.println("List ready to check. values in list are :"+aList);
}
} catch (IOException e) {
System.out.println(e);
}
if (string.equals(textField.getText())) {
JOptionPane.showMessageDialog(null, "Hooray!");
}
else {
JOptionPane.showMessageDialog(null, "Wrong!");
}
}
}
}
this is my code, I just want to make a receipt that when you check the checkbox theres value in it and it prints the label with the value consecutively
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class GUI extends JFrame implements ActionListener
{
private JLabel label;
private JCheckBox checkbox,checkbox2,checkbox3,checkbox4,checkbox5,
checkbox6,checkbox7,checkbox8,checkbox9,
checkbox10,checkbox11,checkbox12,checkbox13,checkbox14,checkbox15,
checkbox16,checkbox17,checkbox18,checkbox19,checkbox20;
private JButton button;
public GUI()
{
Container pane= getContentPane();
pane.setLayout(new GridLayout(15,1));
JPanel jp= new JPanel();
label= new JLabel("McDonald's");
checkbox = new JCheckBox("Cheese Burger");
checkbox2 = new JCheckBox("Big Mac");
checkbox3 = new JCheckBox("Big n' Tasty");
checkbox4 = new JCheckBox("McSpicy");
checkbox5 = new JCheckBox("Quarter Pounder with Cheese");
checkbox6 = new JCheckBox("Double Cheeseburger");
checkbox7 = new JCheckBox("McChicken Sandwich");
checkbox8 = new JCheckBox("Filet-O-Fish");
checkbox9 = new JCheckBox("Cheeseburger Deluxe");
checkbox10 = new JCheckBox("Burger Mcdo");
checkbox11 = new JCheckBox("Chicken Filet with Drinks");
checkbox12 = new JCheckBox("Spaghetti with Drinks");
checkbox13 = new JCheckBox("Hot Fudge Sundae ");
checkbox14 = new JCheckBox("Caramel Sundae");
checkbox15 = new JCheckBox("Large Mcdo French Fries");
checkbox16 = new JCheckBox("Chicken Nuggets with coke");
checkbox17 = new JCheckBox("Coke Float");
checkbox18 = new JCheckBox("Green Apple Float");
checkbox19 = new JCheckBox("Crispy Chicken with rice");
checkbox20 = new JCheckBox("Oreo Sundae");
button = new JButton("Order Now");
add(label);
pane.add(checkbox);
pane.add(checkbox2);
pane.add(checkbox3);
pane.add(checkbox4);
pane.add(checkbox5);
pane.add(checkbox6);
pane.add(checkbox7);
pane.add(checkbox8);
pane.add(checkbox9);
pane.add(checkbox10);
pane.add(checkbox11);
pane.add(checkbox12);
pane.add(checkbox13);
pane.add(checkbox14);
pane.add(checkbox15);
pane.add(checkbox16);
pane.add(checkbox17);
pane.add(checkbox18);
pane.add(checkbox19);
pane.add(checkbox20);
add(button);
add(jp, BorderLayout.SOUTH);
label.setHorizontalAlignment(JLabel.CENTER);
button.setSize(10,10);
button.addActionListener(this);
setSize(500,550);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String gulp = e.getActionCommand();
{
if ( gulp.equals("Order Now"))
{
new Receipt();
setVisible(true);
dispose();
}
}
}
public static void main(String[] args)
{
GUI r= new GUI();
}
}
here is my second code, this is the format of the receipt I want to achieve
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class Receipt extends JFrame
{
private JLabel label,label2,label3,label4,label5,
label6,label7,label8,label9,label10;;
public Receipt()
{
Container pane= getContentPane();
pane.setLayout(new GridLayout(13,1));
label= new JLabel("MC DONALD'S");
label2= new JLabel("McDonald's Tandang Sora");
label3= new JLabel("#22 Tandang Sora Corner, Commonwealth Avenue, Quezon City");
label4= new JLabel("Telephone# (02)86236");
label5= new JLabel("MACHINE SERIAL NUMBER: D123HJ01");
label6= new JLabel("Card Issuer: Sharina Tortoles");
label7= new JLabel("Account Number# 337163990");
label8= new JLabel("February 22, 2014 12:45");
label9= new JLabel("Thank You for choosing Mcdonald's");
label10= new JLabel("Please come again");
label.setHorizontalAlignment(JLabel.CENTER);
label2.setHorizontalAlignment(JLabel.CENTER);
label3.setHorizontalAlignment(JLabel.CENTER);
label4.setHorizontalAlignment(JLabel.CENTER);
label5.setHorizontalAlignment(JLabel.CENTER);
label6.setHorizontalAlignment(JLabel.CENTER);
label7.setHorizontalAlignment(JLabel.CENTER);
label8.setHorizontalAlignment(JLabel.CENTER);
label9.setHorizontalAlignment(JLabel.CENTER);
label10.setHorizontalAlignment(JLabel.CENTER);
pane.add(label, BorderLayout.NORTH);
pane.add(label2);
pane.add(label3);
pane.add(label4);
pane.add(label5);
pane.add(label6);
pane.add(label7);
pane.add(label8);
pane.add(label9);
pane.add(label10);
setSize(500,500);
setVisible(true);
}
public static void main(String[] args)
{
Receipt g= new Receipt();
}
}
Hope that it is clear to you what I want to happen with code
I guess EnumSet is what you are looking for:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.List;
import javax.swing.*;
enum Receipt {
CheeseBurger("Cheese Burger"),
BigMac("Big Mac"),
BigNTasty("Big n' Tasty"),
McSpicy("McSpicy"),
QuarterPounderWithCheese("Quarter Pounder with Cheese"),
DoubleCheeseburger("Double Cheeseburger"),
McChickenSandwich("McChicken Sandwich");
//JCheckBox("Filet-O-Fish"),
//JCheckBox("Cheeseburger Deluxe"),
//JCheckBox("Burger Mcdo"),
//JCheckBox("Chicken Filet with Drinks"),
//JCheckBox("Spaghetti with Drinks"),
//JCheckBox("Hot Fudge Sundae "),
//JCheckBox("Caramel Sundae"),
//JCheckBox("Large Mcdo French Fries"),
//JCheckBox("Chicken Nuggets with coke"),
//JCheckBox("Coke Float"),
//JCheckBox("Green Apple Float"),
//JCheckBox("Crispy Chicken with rice"),
//JCheckBox("Oreo Sundae");
private final String str;
private Receipt(String str) {
this.str = str;
}
#Override public String toString() {
return str;
}
}
public class GUI2 {
private JButton button = new JButton(new AbstractAction("Order Now") {
#Override public void actionPerformed(ActionEvent e) {
EnumSet<Receipt> r = EnumSet.noneOf(Receipt.class);
for (ReceiptCheckBox c: list) {
if (c.isSelected()) {
r.add(c.getReceipt());
}
}
JOptionPane.showMessageDialog((JComponent) e.getSource(), r);
}
});
private List<ReceiptCheckBox> list = new ArrayList<>(Receipt.values().length);
public JComponent makeUI() {
JPanel p = new JPanel();
for (Receipt r: Receipt.values()) {
ReceiptCheckBox c = new ReceiptCheckBox(r);
list.add(c);
p.add(c);
}
JPanel panel = new JPanel(new BorderLayout());
panel.add(new JLabel("McDonald's"), BorderLayout.NORTH);
panel.add(button, BorderLayout.SOUTH);
panel.add(p);
return panel;
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
#Override public void run() {
createAndShowGUI();
}
});
}
public static void createAndShowGUI() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.getContentPane().add(new GUI2().makeUI());
f.setSize(320, 240);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
class ReceiptCheckBox extends JCheckBox {
private final Receipt receipt;
public ReceiptCheckBox(Receipt receipt) {
super(receipt.toString());
this.receipt = receipt;
}
public Receipt getReceipt() {
return receipt;
}
}
I get this error at this line:
private List<Contractor> contractors = new ArrayList<Contractor>();
It says contractor cannot be resolved to a type. Now what I did here was I had a customer class. I needed to create a contractor class too which is exactly the same as the customer class. So I copied everything from the customer class and created a contractor class. I then added everything in the code below which I thought is the same for the customer class, but something is wrong.
public class SwimCalc extends JFrame implements ActionListener {
private JTabbedPane jtabbedPane;
private JPanel Customers;
private JPanel Contractors;
private List<Customer> customers = new ArrayList<Customer>();
// this fails
private List<Contractor> contractors = new ArrayList<Contractor>();
JTextArea NameTextCustomers, ExistTextCustomers, MessageTextCustomers,
NameTextContractors, ExistTextContractors, MessageTextContractors;
JTextField lengthTextPool, widthTextPool, depthTextPool, volumeTextPool;
public SwimCalc() {
setTitle("Volume Calculator");
setSize (300, 200);
JPanel topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );
createCustomers();
createContractors();
jtabbedPane = new JTabbedPane();
jtabbedPane.addTab("Customer", Customers);
topPanel.add(jtabbedPane, BorderLayout.CENTER);
}
}
Here is the contractor class
public JPanel createContractors(){
Contractors = new JPanel();
Contractors.setLayout(null);
NameTextContractors = new JTextArea("Select Add Contractor to Add Contractor." +
"\nSelect Refresh to Refresh This Pane.");
NameTextContractors.setLineWrap(true);
NameTextContractors.setBounds(10, 10, 390, 150);
Contractors.add(NameTextContractors);
JButton Exit = new JButton("Exit");
Exit.setBounds(30,170,80,20);
Exit.addActionListener(this);
Exit.setBackground(Color.white);
Contractors.add(Exit);
JButton AddContractors = new JButton("Add Contractor");
AddContractors.setBounds(130,170,120,20);
AddContractors.setBackground(Color.white);
Contractors.add(AddContractors);
JButton Refresh = new JButton("Refresh");
Refresh.setBounds(260,170,80,20);
Refresh.setBackground(Color.white);
Contractors.add(Refresh);
ExistTextContractors = new JTextArea("File Contractor.txt does not exist yet." +
"\nIt will be created when you add Contractor.");
ExistTextContractors.setBounds(10, 200, 390, 60);
ExistTextContractors.setLineWrap(true);
Contractors.add(ExistTextContractors);
final JTextArea contArea = new JTextArea(6, 30);
final JTextArea ExistTextContractors;
ExistTextContractors = new JTextArea(2, 30);
ExistTextContractors.setLineWrap(true);
ExistTextContractors.setWrapStyleWord(true);
AddContractors.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e){
new Contractor("Contractor", SwimCalc.this);
}
});
Contractors.add(contArea);
Contractors.add(AddContractors);
Contractors.add(Refresh);
Refresh.setMnemonic('R');
Refresh.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
NameTextContractors.setText ("");
try{
File contOpen = new File("Contractor.txt");
FileReader contAreaIn = new FileReader(contOpen);
contArea.read(contAreaIn, contOpen.getAbsolutePath());
ExistTextContractors.setText("File exists and can be read.");
}
catch (IOException e3){
ExistTextContractors.setText("The file could not be read." + e3.getMessage());
}
}
}
);
return Contractors;
}
class Contractor extends JFrame
{
private String[] states = {"AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE",
"FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME",
"MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ",
"NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD",
"TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"};
private JComboBox StateList = new JComboBox(states);
private JTextField NameText = new JTextField(25);
private JTextField AddressText = new JTextField(25);
private JTextField CityText = new JTextField(25);
private JTextField ZipText = new JTextField(9);
private JTextField PhoneText = new JTextField(10);
private JTextField MessageTextContractors = new JTextField(30);
private static final long serialVersionUID = 1L;
private AddContButtonHandler addConHandler = new AddContButtonHandler();
private SwimCalc parent;
public Contractor(String who, SwimCalc _parent) {
popUpWindow (who);
parent = _parent;
}
public void popUpWindow(final String who) {
final JFrame popWindow;
popWindow = new JFrame(who);
popWindow.setSize(425, 350);
popWindow.setLocation(100, 100);
popWindow.setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container c = new Container();
popWindow.add(c);
c.setLayout(new FlowLayout());
JPanel one = new JPanel();
JPanel two = new JPanel();
JPanel three = new JPanel();
JPanel four = new JPanel();
JPanel five = new JPanel();
JPanel six = new JPanel();
one.add(new JLabel(who + " Name "));
one.add(NameText);
two.add(new JLabel("Address "));
two.add(AddressText);
three.add(new JLabel("City "));
three.add(CityText);
four.add(new JLabel("State "));
StateList.setSelectedIndex(0);
four.add(StateList);
four.add(new JLabel("ZIP"));
four.add(ZipText);
four.add(new JLabel("Phone"));
four.add(PhoneText);
JButton addwho = new JButton("Add " + who);
addwho.setMnemonic('A');
JButton close = new JButton("Exit");
close.setMnemonic('C');
JButton deleteFile = new JButton("Delete File");
deleteFile.setMnemonic('D');
five.add(addwho);
five.add(close);
five.add(deleteFile);
MessageTextContractors.setEditable(false);
MessageTextContractors.setHorizontalAlignment(JTextField.CENTER);
six.add(MessageTextContractors);
c.add(one);
c.add(two);
c.add(three);
c.add(four);
c.add(five);
c.add(six);
deleteFile.setToolTipText("Delete File");
addwho.setToolTipText("Add "+ who);
close.setToolTipText("Exit");
if (who == "Contractor")
addwho.addActionListener(addConHandler);
close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
NameText.setText("");
AddressText.setText("");
CityText.setText("");
ZipText.setText("");
PhoneText.setText("");
MessageTextContractors.setText("");
popWindow.dispose();
}
}
);
deleteFile.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MessageTextContractors
.setText("");
if (who.equals("Contractor")) {
File file = new File("Contractor.txt");
boolean conFileDeleted = file.delete();
if (conFileDeleted) {
MessageTextContractors
.setText("Contractor file has been deleted");
} else {
MessageTextContractors
.setText("There was an error in deleting file");
}
}
}
}
);
}
class AddContButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent addConHandler) {
int StateIndex;
try {
File file = new File("Contractor.txt");
StringBuilder sb = new StringBuilder();
boolean success = file.createNewFile();
if (success) {
MessageTextContractors
.setText("Contractor.txt file created file added");
} else if (file.canWrite()) {
MessageTextContractors
.setText("Writing data to Contractor.txt, file added");
} else {
MessageTextContractors.setText("Cannot create file: Contractor.txt");
}
try {
FileWriter fileW = new FileWriter("Contractor.txt", true);
sb.append(NameText.getText());
sb.append("\n");
sb.append(AddressText.getText());
sb.append("\n");
sb.append(CityText.getText());
sb.append("\n");
StateIndex = StateList.getSelectedIndex();
sb.append(states[StateIndex]);
sb.append("\n");
sb.append(ZipText.getText());
sb.append("\n");
sb.append(PhoneText.getText());
sb.append("\r\n");
fileW.write(sb.toString());
parent.setField(sb.toString());
fileW.close();
MessageTextContractors.setText("A new Contractor has been added!");
ExistTextContractors.setText ("File Contractor.txt exists and can be read from!");
FileReader fileR = new FileReader("Contractor.txt");
BufferedReader buffIn = new BufferedReader(fileR);
String textData = buffIn.readLine();
buffIn.close();
}
catch (IOException e1) {
JOptionPane.showMessageDialog(null, e1.getMessage(), "ERROR", 2);
}
NameText.setText("");
AddressText.setText("");
CityText.setText("");
ZipText.setText("");
PhoneText.setText("");
}
catch (IOException e1) {
}
}
}
public void actionPerformed(ActionEvent event){
}
private void Exit_pressed(){
System.exit(0);
}
}
Usually this is an import problem. If you're using a good IDE (i.e. Eclipse or Intellij) it will import everything you need if you ask it.)
See Foo cannot be resolved to a type
I deleted everything in my /target folder and it worked for me.