I recently finished up a GUI where a user can input criteria, and get results adhering to said conditions. The program works result wise, but I'm having trouble getting my textField in my GUI to read my terminal window result. My code for the GUI is as followed:
package project205;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class HouseListGUI extends JFrame
{
//GUI Components
HouseList availableHouses = new HouseList("src/houses.txt");
JLabel cLab = new JLabel("Criteria");
JLabel minLab = new JLabel("Min");
JLabel maxLab = new JLabel("Max");
JLabel pLab = new JLabel("Price");
JLabel aLab = new JLabel("Area");
JLabel bLab = new JLabel("Bedrooms");
JTextField pMin = new JTextField(10);
JTextField pMax = new JTextField(10);
JTextField aMin = new JTextField(10);
JTextField aMax = new JTextField(10);
JTextField bMin = new JTextField(10);
JTextField bMax = new JTextField(10);
JTextArea results = new JTextArea(20, 40);
JButton sButton = new JButton("Search");
JButton qButton = new JButton("Quit");
public HouseListGUI()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400,300);
setVisible(true);
Container c = getContentPane();
c.setLayout(new GridLayout(5,3,10,10));
c.add(cLab);
c.add(minLab);
c.add(maxLab);
c.add(pLab);
c.add(pMin);
c.add(pMax);
c.add(aLab);
c.add(aMin);
c.add(aMax);
c.add(bLab);
c.add(bMin);
c.add(bMax);
c.add(sButton);
c.add(results);
c.add(qButton);
sButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String pmn = pMin.getText();
String pmx = pMax.getText();
String amn = aMin.getText();
String amx = aMax.getText();
String bmn = bMin.getText();
String bmx = bMax.getText();
int pmn1 = Integer.parseInt(pmn);
int pmx1 = Integer.parseInt(pmx);
int amn1 = Integer.parseInt(amn);
int amx1 = Integer.parseInt(amx);
int bmn1 = Integer.parseInt(bmn);
int bmx1 = Integer.parseInt(bmx);
Criteria theCriteria = new Criteria(pmn1, pmx1, amn1, amx1, bmn1, bmx1);
availableHouses.printHouses(theCriteria);
results.setText("");
}
});
qButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
);
}
public static void main(String[] args)
{
//HouseList availableHouses = new HouseList("src/houses.txt");
HouseListGUI g1 = new HouseListGUI();
g1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
g1.setSize(1000,500);
g1.show();
}
}
I would like the results of the code line availableHouses.printHouses(theCriteria); which returns a type void to be printed in the textArea results
I've tried using type cast to cast the void as a string and putting that into results, ie:
results.setText((String)availableHouses.printHouses(theCriteria);
But Java's not having that.
TL;DR:
How might one take a terminal resulting from a method call of type void, and printing that as a type String into a textArea in the context of a GUI?
for further clarification:
my terminal window looks like this:
https://i.stack.imgur.com/ZTZFC.jpg
and my GUI looks like this:
https://i.stack.imgur.com/dCxbZ.jpg
and I want my terminal to be in the middle box in the last row.
Thanks for any advice/tips!