• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Convert working program to display in GUI

 
sam spadeco
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
inv.printCardCollection();
inv.printTotalValue();

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() {
initComponents();
}

/** 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);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(95, 95, 95)
.addComponent(jButton1)))
.addContainerGap(19, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(32, 32, 32)
.addComponent(jButton1)
.addContainerGap(35, Short.MAX_VALUE))
);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.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
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

CR
 
sam spadeco
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you I will look at the Java Tutorial on buttons.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic