Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do i save variables after closing the jframe and re-opening it? Code Below: import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BoxLayout; import

How do i save variables after closing the jframe and re-opening it? Code Below:

import java.awt.BorderLayout;

import java.awt.Dimension;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.BoxLayout;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTextField;

public class RecipeFinder {

public static void main(String[] args) {

//JFrame

JFrame frame = new JFrame("The Recipe Finder");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setPreferredSize(new Dimension(500,400));

//JPanel

JPanel entry = new JPanel();

entry.setLayout(new BoxLayout(entry, BoxLayout.Y_AXIS));

//JLabel

JLabel insert = new JLabel("Insert Food/Ingredients");

entry.add(insert);

//JTextField(s)

JTextField foodOne = new JTextField();

foodOne.setPreferredSize(new Dimension(200,24));

entry.add(foodOne);

JTextField foodTwo = new JTextField();

foodTwo.setPreferredSize(new Dimension(200,24));

entry.add(foodTwo);

//JButton(s)

JButton addTextBox = new JButton("Add");

addTextBox.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

JTextField newBox = new JTextField();

newBox.setPreferredSize(new Dimension(200,24));

entry.add(newBox);

entry.revalidate();

frame.invalidate();

}

});

JButton search = new JButton("Search Recipes");

JPanel buttonPanel = new JPanel();

buttonPanel.add(addTextBox);

buttonPanel.add(search);

JPanel rootPanel = new JPanel();

rootPanel.setLayout(new BorderLayout());

rootPanel.add(entry, BorderLayout.CENTER);

rootPanel.add(buttonPanel, BorderLayout.SOUTH);

JScrollPane rootEntry = new JScrollPane(rootPanel);

rootEntry.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

rootEntry.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

//FrameWork

frame.add(rootEntry);

frame.pack();

frame.setVisible(true);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Design A Practical Approach

Authors: Marilyn Campbell

1st Edition

1587193175, 978-1587193170

More Books

Students also viewed these Databases questions