
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 3 steps

Knowledge Booster
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
- can someone help me resize the picture in Java. This is my code: import java.awt.*;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import javax.imageio.ImageIO; class ImageDisplayGUI { public static void main(String[] args) { SwingUtilities.invokeLater(() -> { createAndShowGUI(); }); } private static void createAndShowGUI() { JFrame frame = new JFrame("Bears"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(800, 600); frame.setLayout(new BorderLayout()); // Load and display the JPG image try { BufferedImage image = ImageIO.read(new File("two bears.png")); // Replace with your image path ImageIcon icon = new ImageIcon(image); JLabel imageLabel = new JLabel(icon); frame.add(imageLabel, BorderLayout.CENTER); } catch (IOException e) { // Handle image loading error…arrow_forwardPlease add the code after this one. The code has to be in java eclipse. Please add comments in what you are doing. I'll appreciate it public class Computer { private String ModelNumber; private String BrandName; private String manufacturingDate; private int NumberOfCores; //Constructor a public Computer() {} //Construct a computer object with model, BrandName, NumberOfCoresComputer (String ModelNumber, String BrandName, String manufacturingDate, int NumberOfCores){ this.ModelNumber=ModelNumber; this.BrandName=BrandName; this.manufacturingDate=manufacturingDate; this.NumberOfCores=NumberOfCores;}//generate getters/setterspublic String getModel() { return ModelNumber;} public void setModel(String ModelNumber) { ModelNumber = ModelNumber;} public String getBrandName() { return BrandName;} public void setBrandName(String brandName) { BrandName = brandName;} public String getManufacturingDate() { return manufacturingDate;} public void setManufacturingDate(String…arrow_forwardhow to do this in java that functions with the main class in the first image and can be compared with the container class in the second imagearrow_forward
- You have to use comment function to describe what each line does import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class PreferenceData { private final List<Student> students; private final List<Project> projects; private int[][] preferences; private static enum ReadState { STUDENT_MODE, PROJECT_MODE, PREFERENCE_MODE, UNKNOWN; }; public PreferenceData() { super(); this.students = new ArrayList<Student>(); this.projects = new ArrayList<Project>(); } public void addStudent(Student s) { this.students.add(s); } public void addStudent(String s) { this.addStudent(Student.createStudent(s)); } public void addProject(Project p) { this.projects.add(p); } public void addProject(String p) { this.addProject(Project.createProject(p)); } public void createPreferenceMatrix() { this.preferences = new…arrow_forwardThe first one is answered as follows. Help with the second one. package test;import javax.swing.*;import java.awt.*;import java.awt.event.*; public class JavaApplication1 { public static void main(String[] arguments) { JFrame.setDefaultLookAndFeelDecorated(true);JFrame frame = new JFrame("print X and Y Coordinates");frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout());frame.setSize(500,400); final JTextField output = new JTextField();;frame.add(output,BorderLayout.SOUTH); frame.addMouseListener(new MouseListener() {public void mousePressed(MouseEvent me) { }public void mouseReleased(MouseEvent me) { }public void mouseEntered(MouseEvent me) { }public void mouseExited(MouseEvent me) { }public void mouseClicked(MouseEvent me) {int x = me.getX();int y = me.getY();output.setText("Coordinate X:" + x + "|| Coordinate Y:" + y);}}); frame.setVisible(true);}}arrow_forwardThere is something wrong with this Java program but I do not know what it is. can someone help 2 import java.awt.*; 3 import javax.swing.*; 4 import java.awt.event.*; 5 import java.awt.Color; 6 7 8 class Radiobutton extends JFrame { 9 10 11 JRadioButton jRadioButton1; 12 JRadioButton jRadioButton2; 13 JButton jButton; 14 ButtonGroup G1; 15 JLabel L1; 16 17 public Radiobutton() 18 { 19 this.setLayout(null); 20 jRadioButton1 = new JRadioButton(); 21 jRadioButton2 = new JRadioButton(); 22 jButton = new JButton("Click"); 23 G1 = new ButtonGroup(); 24 L1 = new JLabel("Qualification"); 25 26 jRadioButton1.setText("Under-Graduate"); 27 jRadioButton2.setText("Graduate"); 28 29 jRadioButton1.setBounds(120, 30, 120, 50); 30 jRadioButton2.setBounds(250, 30, 80, 50); 31 jButton.setBounds(125, 90, 80, 30); 32 L1.setBounds(20, 30, 150, 50); 33 34 this.add(jRadioButton1); 35…arrow_forward
- Please help me create a matching game using java and 2D arrays. Create a reset button and titlearrow_forwardI know it is a lot but can someone explain (with comments) line by line what is happening in the below Java program. It assists in my learning/gives me a deeper understanding. Please and thank you! Source code: import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.SwingUtilities; class ProductCalculator { public static int calculateProduct(int[] numbers, int index) { if (index == numbers.length - 1) { return numbers[index]; } else { return numbers[index] * calculateProduct(numbers, index + 1); } }} class RecursiveProductCalculatorView extends JFrame { private JTextField[] numberFields; private JButton calculateButton; private JLabel resultLabel; public RecursiveProductCalculatorView() { setTitle("Recursive Product Calculator"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new GridLayout(7, 1)); numberFields =…arrow_forwardGuidelines are creating a cardlayout with 3 cards: login, fred and bob. import java.awt.event.*;import javax.swing.*;import java.awt.*;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import java.awt.BorderLayout;import java.awt.CardLayout;import java.awt.FlowLayout;import java.awt.Color;import java.awt.Container;import java.awt.event.ActionEvent;import java.awt.event.ActionListener; public class SimpleCardWindow extends JFrame implements ActionListener {public static final int WIDTH = 300;public static final int HEIGHT = 300; private CardLayout theCardsLayoutManager;private JPanel theCardsPanel;private JTextField userTextField;private JTextField passwordTextField;private JButton loginButton;private JButton bobWordButton;private JTextField bobEntryTextField;private JTextArea bobDisplayTextArea;private JButton bobReturnButton;private JPanel fredCard;private JPanel fredButtonPanel;private JButton fredRedColorButton;private JButton…arrow_forward
- Please help me with this using java. A starters code is provided (I created a starters code). For more info refer to the image provided. Please ensure tge code works Starter code:import javax.swing.*; import java.applet.*; import java.awt.event.*; import java.awt.*;public class halloween extends Applet implements ActionListener{ int hallow[] [] = ? int rows = 4; int cols = 3; JButton pics[] = new JButton [rows * cols]; public void init () { Panel grid = new Panel (new GridLayout (rows, cols)); int m = 0; for (int i = 0 ; i < rows ; i++) { for (int j = 0 ; j < cols ; j++) { pics [m] = new JButton (createImageIcon ("back.png")); pics [m].addActionListener (this); pics [m].setActionCommand (m + ""); pics [m].setPreferredSize (new Dimension (128, 128)); grid.add (pics [m]); } }m++; }}add (grid); }public void actionPerformed (ActionEvent…arrow_forwardI need help With this problem for JAVAFX. if possible can it work in eclipse. GeometricObjects code public abstract class GeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated; /** Construct a default geometric object */ protected GeometricObject() { dateCreated = new java.util.Date(); } /** Construct a geometric object with color and filled value */ protected GeometricObject(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; } /** Return color */ public String getColor() { return color; } /** Set a new color */ public void setColor(String color) { this.color = color; } /** Return filled. Since filled is boolean, * the get method is named isFilled */ public boolean isFilled() { return filled; } /** Set a new filled */ public void setFilled(boolean filled) { this.filled = filled; } /** Get dateCreated */ public java.util.Date getDateCreated() { return dateCreated; }…arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education