trying to use Integer.parseInt() for a class project but for some reason it just isnt working and comes up with Syntax error on tokens, Resources expected insteadJava(1610612973)
Integer issue is at the top in checkInt() boolean
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.Integer;
public class RentalApp{
public static boolean checkInt(String s)
{
try(Integer.parseInt(s))
{
}
catch (Exception e)
{
}
}
public static void main(String[] args)
{
final int WINDOW_WIDTH = 700;
final int WINDOW_HEIGHT = 450;
// Create JFrame Window
JFrame window = new JFrame();
window.setTitle("Vehicle Rental System");
window.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create and add text
JLabel text = new JLabel("Select Vehicle Type:");
window.add(text);
// Create and add dropdown menu
String[] choices = {"Car", "Truck", "Bike"};
final JComboBox c1 = new JComboBox(choices);
c1.setPreferredSize(new Dimension (80, 25));
window.add(c1);
// Create and add more text
JLabel text2 = new JLabel("Enter Number of Rental Days:");
window.add(text2);
// Create and add text field
final JTextField dayInput = new JTextField(5);
window.add(dayInput);
// Create and add button
JButton button = new JButton("Calculate Rent");
window.add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
switch (new String((String) c1.getSelectedItem())){
case ("Car"):
//car code
break;
case ("Truck"):
//truck code
break;
case ("Bike"):
//bike code
break;
}
}
});
window.setLayout(new FlowLayout());
window.setVisible(true);
}
}
I tried importing java.lang.Integer but that doesn't help, this is all of the code, not finished obviously