why does my java code do not run? I'm using JGRASP import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Font; import java.awt.Image; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import javax.imageio.ImageIO; import javax.swing.Box; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @SuppressWarnings("serial") public class MainMenu extends JPanel { JLabel picLabel, title; JButton button; private Panel panel_1; private Panel panel_2; static JFrame frame; public void createAndShowGUI() throws IOException { JPanel panel = new JPanel(new BorderLayout()); Image image = ImageIO.read(this.getClass().getResource("food_logo.png")); Image imageScaled = image.getScaledInstance(350, 300, Image.SCALE_SMOOTH); ImageIcon imageIcon = new ImageIcon(imageScaled); picLabel = new JLabel(imageIcon); Box right = Box.createVerticalBox(); panel_1 = new Panel(); title = new JLabel("898 Food Restaurant"); title.setAlignmentX(Component.CENTER_ALIGNMENT); title.setAlignmentY(0.0f); title.setHorizontalAlignment(SwingConstants.CENTER); title.setFont(new Font("Serif", Font.ITALIC + Font.BOLD, 18)); title.setForeground(Color.BLUE); // Button, with filler button = new JButton("Order Food Now >>"); panel_1.add(button); button.setAlignmentX(Component.LEFT_ALIGNMENT); panel.add(picLabel, BorderLayout.CENTER); panel.add(right, BorderLayout.SOUTH); right.add(title); right.add(panel_1); add(panel); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FoodMenu food; try { food = new FoodMenu(); food.createAndShowGUI(); food.setVisible(true); setVisible(false); frame.dispose(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); } public static void main(String args[]) throws IOException { MainMenu main = new MainMenu(); main.createAndShowGUI(); frame = new JFrame(); frame.setTitle("898 Food Ordering System"); frame.getContentPane().add(main); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

why does my java code do not run? I'm using JGRASP

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
 
 
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
 
import javax.imageio.ImageIO;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
@SuppressWarnings("serial")
public class MainMenu extends JPanel {
JLabel picLabel, title;
JButton button;
private Panel panel_1;
private Panel panel_2;
static JFrame frame;
 
public void  createAndShowGUI() throws IOException {
JPanel panel = new JPanel(new BorderLayout());
Image image = ImageIO.read(this.getClass().getResource("food_logo.png"));
Image imageScaled = image.getScaledInstance(350, 300, Image.SCALE_SMOOTH);
ImageIcon imageIcon = new ImageIcon(imageScaled);
picLabel = new JLabel(imageIcon);
Box right = Box.createVerticalBox();
panel_1 = new Panel();
title = new JLabel("898 Food Restaurant");
title.setAlignmentX(Component.CENTER_ALIGNMENT);
title.setAlignmentY(0.0f);
title.setHorizontalAlignment(SwingConstants.CENTER);
title.setFont(new Font("Serif", Font.ITALIC + Font.BOLD, 18));
title.setForeground(Color.BLUE);
 
// Button, with filler
button = new JButton("Order Food Now >>");
panel_1.add(button);
button.setAlignmentX(Component.LEFT_ALIGNMENT);
 
panel.add(picLabel, BorderLayout.CENTER);
panel.add(right, BorderLayout.SOUTH);
right.add(title);
right.add(panel_1);
add(panel);
 
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
FoodMenu food;
try {
food = new FoodMenu();
food.createAndShowGUI();
food.setVisible(true);
setVisible(false);
frame.dispose();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
}
 
public static void main(String args[]) throws IOException {
MainMenu main = new MainMenu();
main.createAndShowGUI();
frame = new JFrame();
frame.setTitle("898 Food Ordering System");
frame.getContentPane().add(main);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}

 

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Running Time of Application
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education