File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Convert working program to display in GUI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Convert working program to display in GUI " Watch "Convert working program to display in GUI " New topic

Convert working program to display in GUI

sam spadeco

Joined: Apr 10, 2007
Posts: 2
I have a working program that outputs the result, I now need to get the output to display in a GUI window.

I'm using a inv,printInventory(); and a inv.printTotalInventory(); to display the result.

// display the inventory on the screen

What I need help with is getting the results to display in a GUI (JTextField??) after pressing the CardCollecion button (JButton??). Any sugesstion to get me started would be greatly appreciated.

I guess I just need to understand how to connect the inv.printCardCollection(); to a button and display it in the text window, or would it make more sense to use a JTable

The output looks like this in my current program.

PlayerName CardBrand Year CardNumber Value
Todd Helton Topps 2005 123 $1
Barry Bonds Fleer 1998 23 $12

What I have created so far for my Java Window.


public class NewJPanel extends javax.swing.JPanel {

/** Creates new form NewJPanel */
public NewJPanel() {

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();

jTextField1.setText("Card Collcetion Results");

jButton1.setText("Card Collection");

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
.addGap(18, 18, 18)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(95, 95, 95)
.addContainerGap(19, Short.MAX_VALUE))
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(32, 32, 32)
.addContainerGap(35, Short.MAX_VALUE))

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
}// </editor-fold>

// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
// End of variables declaration
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 36486
Welcome to the Ranch.
I am afraid I shall make one unwelcome suggestion: stop using the GUI builder on NetBeans until you understand the syntax of adding Components.
Go into the Swing part of the Java Tutorial. Find the bit about "how to use buttons" and about "how to use text fields" or text areas.

Just beware: the Java tutorials have a tendency to put lots in the main method, which is convenient for writing short examples but doesn't count as object-oriented programming. The format they use in this first example in the Java Tutorial, however, is excellent. Only you don't need to say "frame.getContentPane().add(xyz);" in Java 5 or Java 6, you just say "frame.add(xyz);".

The Java Tutorials also tend to use the syntax "addActionListener(this)" which I look on as an abomination. I wrote about it here, last year, and still think that is the correct way to do it. You might be able to persuade NetBeans to write an anonymous actionListener for you by filling in a blank template.

I hope you are able to work out what to do with your Swing app. All the best.

sam spadeco

Joined: Apr 10, 2007
Posts: 2
Thank you I will look at the Java Tutorial on buttons.
I agree. Here's the link:
subject: Convert working program to display in GUI
Similar Threads
Storing JTextField to variable
Pressing a button to open a new window
Problem With GUI of Net Beans
Reading RS232 and displaying contents on Frame
Networked Programs that work across countries