# dusting off the old java skills!



## Easy Rhino (Feb 26, 2010)

i figure i should probably dust off my java skills and keep my brain fresh. so i have decided to create a fairly simple program for an upcoming wine party i am hosting. essentially the program should... 

1)using a gui, ask the guest to enter their name, wine region, vineyard, grape type and vintage
2)store that information in a text file using commas as a delimiter
3)repeat for the number of guests attending
4)when all the guests have entered their info it should ask to start the voting process
5)this will open up a window each time a vote button has been pressed containing the list of wines in a readable format.
6)the guest chooses the wine they would like to vote on using a radio button and then they are prompted to enter a vote between 1 and 10. 
7)they hit enter and then the gui box closes back to the vote box.
8)repeat until end program is called.

-do you guys think using a GUI would be the best or maybe an applet? 
-any idea how to output information from a GUI to a text file keeping the info comma delimited?


----------



## FordGT90Concept (Feb 26, 2010)

Easy Rhino said:


> do you guys think using a GUI would be the best or maybe an applet?


Anything that requires more than one input should take the shape of a GUI.




Easy Rhino said:


> -any idea how to output information from a GUI to a text file keeping the info comma delimited?


Make a class, struct, or array which stores all the info for each object and put a ToString() method in it that always returns the CSV condition of it.  For example, the class should contain members:
-Name
-WineRegion
-Vinyard
-GrapeType
-Vintage

Then when you call ToString(), it should return:

```
name,wineregion,vinyard,grapetype,vintage
```

To load them, use .split() with a comma to get an array of strings and plug them back in where they need to go in the class/struct/array.


----------



## Easy Rhino (Feb 26, 2010)

so far i have a simple 3 button applet. when you click the "enter wine info" button it pops open a GUI that prompts the user to enter specific information. 

i need to get that information which is saved in memory onto a CSV.

multiple users will enter unique info onto this CSV and then when everyone has entered info that CSV will be called for voting purposes.  

here is what i have so far...


```
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.*;

import javax.swing.BorderFactory;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.Border;


public class wineParty extends JApplet implements ActionListener
{
	public String firstName, lastName, wineRegion, vineyard, grape, vintage;
	public static int response;
	
	public JButton wineInfo, enterVote, seeResults;
	
	public JPanel mainPanel = new JPanel();
	
	public Border blueline = BorderFactory.createLineBorder(Color.blue);
	
	public void init()
	{
		wineInfo = new JButton("Enter Wine Info");
		wineInfo.addActionListener(this);
		wineInfo.setFont(new Font("Comic Sans MS", Font.BOLD,20));
		wineInfo.setForeground(Color.blue);
		wineInfo.setBackground(Color.white);
		
		enterVote = new JButton("Enter Your Vote");
		enterVote.addActionListener(this);
		enterVote.setFont(new Font("Comic Sans MS", Font.BOLD,20));
		enterVote.setForeground(Color.blue);
		enterVote.setBackground(Color.white);
		
		seeResults = new JButton("See the Results");
		seeResults.addActionListener(this);
		seeResults.setFont(new Font("Comic Sans MS", Font.BOLD,20));
		seeResults.setForeground(Color.blue);
		seeResults.setBackground(Color.white);
		
		mainPanel.setBackground(Color.white);			
		mainPanel.setLayout(new GridLayout(5, 1));
		mainPanel.add(wineInfo);
		mainPanel.add(enterVote);
		mainPanel.add(seeResults);
		mainPanel.setBorder(blueline);
		
		Container pane = getContentPane();
		pane.add(mainPanel);
	}//end of init
	
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource() == wineInfo)
		{
			displayGUI();
		}
	}
	
	public void displayGUI()
	{
		firstName = JOptionPane.showInputDialog("Enter First Name: ");
		lastName = JOptionPane.showInputDialog("Enter Last Name: ");
		wineRegion = JOptionPane.showInputDialog("Enter Wine Region: ");
		vineyard = JOptionPane.showInputDialog("Enter Vineyard: ");
		grape = JOptionPane.showInputDialog("Enter Grape Information: ");
		vintage = JOptionPane.showInputDialog("Enter Vintage: ");
	}
}//end of class
```


----------



## Wrigleyvillain (Feb 26, 2010)

Java...wine...voting...

Man what ever happened to assembly code and cheap beer?

I'm going to bed now.


----------



## FordGT90Concept (Feb 26, 2010)

```
public String firstName, lastName, wineRegion, vineyard, grape, vintage;
```
That will only handle one object and you need multiple.  Put that in a separate class.  If it describes a bottle of wine, call it "WineBottle."  Once it is in a seperate class, in your main form, make a List of WineBottle with a method to read from CSV and write to CSV.  Every WineBottle will occupy one line in the CSV.


----------

