Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: [Please Help.] Adding values to JList

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question [Please Help.] Adding values to JList

    how to add values from Jtextbox(name) to JList and display the selected values from Jlist.
    Sorry if this is untidy and adding a lot extra thing, i kinda of getting confuse aftertime because of the Jlist problem.

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Color;
     
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    import javax.swing.DefaultListModel;
    import javax.swing.JLabel;
    import javax.swing.JScrollPane;
    import javax.swing.JOptionPane;
    import javax.swing.ListModel;
    import javax.swing.JButton;
    import javax.swing.ListSelectionModel;
     
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.util.Vector;
    import java.util.logging.Level;
    import java.util.logging.Logger;
     
    import javax.swing.GroupLayout;
    import javax.swing.GroupLayout.Alignment;
    import javax.imageio.ImageIO;
     
    public class LHCoinCatalogue extends JFrame {
     
    	private JFrame helpFrame;
     
    	private JPanel contentPane, panel_1;
    	private JPanel JTop, JBottom;
    	private JTabbedPane JCenter;
    	private JButton btnAdd, btnEdit, btnDelete;
     
    	private JTextField coinName, coinWeight, coinYear, coinCountry, coinQuantity; 
    	private JTextArea coinDescription;
     
    	private JComboBox coinGrade, metalType, mintingCompany;
     
    	private JTextField eCoinName, eCoinWeight, eCoinYear, eCountry, eQuantity; 
    	private JTextArea eDescription;
    	private JComboBox eCoinGrade, eMetalType, eCompany;
     
    	private JList eCoinList;
    	private DefaultListModel listModel;
     
    	private JScrollPane listScrollPane;
     
    	private Controller c;
    	private boolean bCoin;
    	private int pos;
    	private int size;
    	private Vector coinVec = null;
     
    	private String sName, sWeight, sYear, sCountry  = null, sQuantity, sDescription  = null;
    	private int sGrade, sType,sCompany;
     
    	String cbGrade[] ={"Not Graded", "Basal State [Poor (PO)]", "continuing Fair (Fr) ", "About or Almost Good (AG)", "Good (G)", "Very Good (VG)", "Fine (F)", "Very Fine (VF)", "Extremely Fine (EF)", "Almost or About Uncirculated (AU) ", "Uncirculated (Unc)", "Brilliant Uncirculated (BU)"};	
    	String cbType[] = {"Aluminium", "Antimony ", "Carbon", "Chromium ", "Copper", "Gold", "Iron", "Lead", "Manganese", "Magnesium ", "Nickel", "Palladium", "Platinum", "Silver", "Tin", "Zinc"};
    	String cbCompany[] = {"CatCoin", "Other"};
     
    	String TestList[] = cbGrade;
     
     
    	 private String basePath = "C:\\Documents and Settings\\Administrator\\Desktop\\Images";
    	 File targetFile;
    	 BufferedImage targetImg;
    	 private static final int baseSize = 128;
    	 //panel_1.add(new JLabel(new ImageIcon(targetImg)));
     
     
    	/**
    	 * Launch the application.
    	 */
     
    	public static void main(String[] args){
     
    		LHCoinCatalogue frame = new LHCoinCatalogue();
    		frame.setVisible(true);
    	}
     
    	/**
    	 * Create the frame.
    	 */
     
    	private LHCoinCatalogue() {
     
    		c = new Controller( );
     
    		// Main Frame
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setBounds(100, 100, 800, 600);
    		contentPane = new JPanel();
    		contentPane.setBorder(new EmptyBorder(0, 0, 0, 0));
    		contentPane.setLayout(new BorderLayout(0, 0));
    		setContentPane(contentPane);
     
    		// Help Frame
    		helpFrame = new JFrame();
    		helpFrame.setLayout(new FlowLayout());
    		helpFrame.setBounds(100, 100, 200, 200);
     
    		// Title Panel
    		JTop = new JPanel();
    		JTop.setBackground(Color.GRAY);
    		contentPane.add(JTop, BorderLayout.NORTH);
     
    		JLabel lblLighthouseCoinCatalogue = new JLabel("Lighthouse Coin Catalogue");
    		lblLighthouseCoinCatalogue.setForeground(Color.BLACK);
    		lblLighthouseCoinCatalogue.setFont(new Font("Arial", Font.BOLD, 18));
    		JTop.add(lblLighthouseCoinCatalogue);
     
     
    		// Bottom Panel (button area)
    		JBottom = new JPanel();
    		JBottom.setBackground(Color.DARK_GRAY);
    		contentPane.add(JBottom, BorderLayout.SOUTH);
     
    		btnAdd = new JButton("Add");
    		btnAdd.addActionListener(new AddHandler());
    		JBottom.add(btnAdd);
     
    		btnEdit = new JButton("Edit");
    		btnEdit.addActionListener(new EditHandler());
    		JBottom.add(btnEdit);
     
    		btnDelete = new JButton("Delete");
    		btnDelete.addActionListener(new DeleteHandler());
    		JBottom.add(btnDelete);
     
     
    		// Center Panel
    		JCenter = new JTabbedPane(JTabbedPane.TOP);
    		contentPane.add(JCenter, BorderLayout.CENTER);
     
    		// first Tab: NewCoin
    		JPanel NewCoin = new JPanel();
    		JCenter.addTab("New Coin", null, NewCoin, null);
    		NewCoin.setLayout(null);
     
    		// first Tab: NewCoin - Page Name
    		JLabel lblAddNewCoin = new JLabel("Add New Coin");
    		lblAddNewCoin.setFont(new Font("Tahoma", Font.PLAIN, 15));
    		lblAddNewCoin.setBounds(285, 11, 100, 14);
    		NewCoin.add(lblAddNewCoin);
     
    		// first Tab: NewCoin - Name
    		JLabel lblName = new JLabel("Name");
    		lblName.setBounds(25, 35, 50, 14);
    		NewCoin.add(lblName);
     
    		coinName = new JTextField();
    		coinName.setBounds(25, 60, 125, 20);
    		coinName.setToolTipText("Name of the Coin. Example: 150th Anniversary of the Founding of Singapore, $150 Dollar");
    		NewCoin.add(coinName);
    		coinName.setColumns(10);
     
    		// first Tab: NewCoin - Weight
    		JLabel lblWeight = new JLabel("Weight");
    		lblWeight.setBounds(180, 35, 50, 14);
     
    		NewCoin.add(lblWeight);
     
    		coinWeight = new JTextField();
    		coinWeight.setBounds(180, 60, 100, 20);
    		coinWeight.setToolTipText("Weight of the Coin");
    		NewCoin.add(coinWeight);
    		coinWeight.setColumns(10);
     
    		// first Tab: NewCoin - Coin Year
    		JLabel lblYearMinted = new JLabel("Year Minted");
    		lblYearMinted.setBounds(25, 90, 75, 14);
    		NewCoin.add(lblYearMinted);
     
    		coinYear = new JTextField();
    		coinYear.setBounds(25, 115, 100, 20);
    		coinYear.setToolTipText("The year of the Coin was created");
    		NewCoin.add(coinYear);
    		coinYear.setColumns(10);
     
    		// first Tab: NewCoin - Coin Country
    		JLabel lblCountryOfMinting = new JLabel("Country of Minting");
    		lblCountryOfMinting.setBounds(25, 150, 125, 14);
    		NewCoin.add(lblCountryOfMinting);
     
    		coinCountry = new JTextField();
    		coinCountry.setBounds(25, 175, 100, 20);
    		coinCountry.setToolTipText("In what coountry was the counted minted in ?");
    		NewCoin.add(coinCountry);
    		coinCountry.setColumns(10);
     
    		// first Tab: NewCoin - Coin Quantity
    		JLabel lblMintagequantityMinted = new JLabel("Mintage (Quantity Minted)");
    		lblMintagequantityMinted.setBounds(25, 205, 150, 14);
    		NewCoin.add(lblMintagequantityMinted);
     
    		coinQuantity = new JTextField();
    		coinQuantity.setBounds(29, 230, 100, 20);
    		coinQuantity.setToolTipText("Total Amount of your coin made");
    		NewCoin.add(coinQuantity);
    		coinQuantity.setColumns(10);
     
    		// first Tab: NewCoin - Description
    		JLabel lblDescription = new JLabel("Description");
    		lblDescription.setBounds(25, 260, 75, 14);
    		NewCoin.add(lblDescription);
     
    		coinDescription = new JTextArea();
    		coinDescription.setBounds(25, 285, 275, 100);
    		NewCoin.add(coinDescription);
    		coinDescription.setColumns(10);
     
    		// first Tab: NewCoin - Coin Grading
    		JLabel lblCoinsGrading = new JLabel("Coin's Grading");
    		lblCoinsGrading.setBounds(456, 35, 100, 14);
    		NewCoin.add(lblCoinsGrading);
     
    		coinGrade = new JComboBox(cbGrade);
    		coinGrade.setBounds(456, 60, 250, 20);
    		coinGrade.setToolTipText("Missing Text");
    		NewCoin.add(coinGrade);
     
    		// first Tab: NewCoin - Coin Metal Type
    		JLabel lblMetalType = new JLabel("Metal Type");
    		lblMetalType.setBounds(456, 125, 75, 14);
    		NewCoin.add(lblMetalType);
     
    		metalType = new JComboBox(cbType);
    		metalType.setBounds(456, 150, 150, 20);
    		metalType.setToolTipText("Material used for creating the coin");
    		NewCoin.add(metalType);
     
    		// first Tab: NewCoin - Minting Company
    		JLabel lblMintingCompany = new JLabel("Minting Company");
    		lblMintingCompany.setBounds(456, 205, 125, 14);
    		NewCoin.add(lblMintingCompany);
     
    		mintingCompany = new JComboBox(cbCompany);
    		mintingCompany.setBounds(456, 230, 250, 20);
    		mintingCompany.setToolTipText("Which company or organization manufacture the coin");
    		NewCoin.add(mintingCompany);
     
    		// first Tab: NewCoin - Add image
    		JButton btnAddImage = new JButton("Add image");
    		btnAddImage.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				browseButtonActionPerformed(e);
    			}
    		});
    		btnAddImage.setBounds(456, 326, 100, 30);
    		NewCoin.add(btnAddImage);
     
     
    		// first tab: NewCoin image panel 
    		JLabel panel_1 = new JLabel();
    		panel_1.add(new JLabel());
    		//panel_1.setLayout(new BorderLayout(0, 0));
            //panel_1.add(new JLabel(new ImageIcon(targetImg)));
    		NewCoin.add(panel_1);
    		setVisible(true);
     
    		// first Tab: NewCoin - Help button
    		JButton btnHelp = new JButton("Help");
    		btnHelp.addActionListener(new HelpHandler());
    		btnHelp.setBounds(675, 400, 75, 25);
    		NewCoin.add(btnHelp);
     
    		// Second Tab: View/Edit 
    		JPanel ViewEditCoin = new JPanel();
    		JCenter.addTab("View/Edit Coin", null, ViewEditCoin, null);
    		ViewEditCoin.setLayout(null);
     
    		// Second Tab: View/Edit - Page Name
    		JLabel lblVieweditCoin = new JLabel("View/Edit Coin");
    		lblVieweditCoin.setFont(new Font("Tahoma", Font.PLAIN, 15));
    		lblVieweditCoin.setHorizontalAlignment(SwingConstants.RIGHT);
    		lblVieweditCoin.setBounds(430, 13, 125, 20);
    		ViewEditCoin.add(lblVieweditCoin);
     
    		// Second Tab: View/Edit - Name
    		JLabel lblName_1 = new JLabel("Name");
    		lblName_1.setBounds(150, 50, 33, 16);
    		ViewEditCoin.add(lblName_1);
     
    		eCoinName = new JTextField();
    		eCoinName.setBounds(150, 75, 150, 20);
    		ViewEditCoin.add(eCoinName);
    		eCoinName.setColumns(10);
     
    		// Second Tab: View/Edit - Weight
    		JLabel lblWeight_1 = new JLabel("Weight (grams)");
    		lblWeight_1.setBounds(325, 50, 50, 16);
    		ViewEditCoin.add(lblWeight_1);
     
    		eCoinWeight = new JTextField();
    		eCoinWeight.setBounds(325, 75, 100, 20);
    		ViewEditCoin.add(eCoinWeight);
    		eCoinWeight.setColumns(10);
     
    		// Second Tab: View/Edit - Coin Year
    		JLabel lblNewLabel = new JLabel("Year Minted");
    		lblNewLabel.setBounds(150, 110, 68, 16);
    		ViewEditCoin.add(lblNewLabel);
     
    		eCoinYear = new JTextField();
    		eCoinYear.setBounds(150, 135, 116, 22);
    		ViewEditCoin.add(eCoinYear);
    		eCoinYear.setColumns(10);
     
    		// Second Tab: View/Edit - Country
    		JLabel lblCountryOfMinting_1 = new JLabel("Country of Minting");
    		lblCountryOfMinting_1.setBounds(150, 170, 104, 16);
    		ViewEditCoin.add(lblCountryOfMinting_1);
     
    		eCountry = new JTextField();
    		eCountry.setBounds(150, 195, 116, 22);
    		ViewEditCoin.add(eCountry);
    		eCountry.setColumns(10);
     
    		// Second Tab: View/Edit - Quantity
    		JLabel lblMintagequantityMinted_1 = new JLabel("Mintage (Quantity Minted)");
    		lblMintagequantityMinted_1.setBounds(150, 230, 148, 16);
    		ViewEditCoin.add(lblMintagequantityMinted_1);
     
    		eQuantity = new JTextField();
    		eQuantity.setBounds(150, 255, 116, 22);
    		ViewEditCoin.add(eQuantity);
    		eQuantity.setColumns(10);
     
    		// Second Tab: View/Edit - Description
    		JLabel lblDescription_1 = new JLabel("Description");
    		lblDescription_1.setBounds(150, 290, 75, 16);
    		ViewEditCoin.add(lblDescription_1);
     
    		eDescription = new JTextArea();
    		eDescription.setBounds(150, 315, 200, 75);
    		ViewEditCoin.add(eDescription);
    		eDescription.setColumns(10);
     
    		// Second Tab: View/Edit - Coin Grading
    		JLabel lblCoinsGrading_1 = new JLabel("Coin's Grading");
    		lblCoinsGrading_1.setBounds(500, 50, 82, 16);
    		ViewEditCoin.add(lblCoinsGrading_1);
     
    		eCoinGrade = new JComboBox(cbGrade);
    		eCoinGrade.setBounds(500, 75, 250, 20);
    		ViewEditCoin.add(eCoinGrade);
     
    		// Second Tab: View/Edit - Coin Metal Type
    		JLabel lblEMetalType = new JLabel("Metal Type");
    		lblEMetalType.setBounds(500, 140, 75, 16);
    		ViewEditCoin.add(lblEMetalType);
     
    		eMetalType = new JComboBox(cbType);
    		eMetalType.setBounds(500, 165, 150, 20);
    		ViewEditCoin.add(eMetalType);
     
    		// Second Tab: View/Edit - Company
    		JLabel lblMintingCompany_1 = new JLabel("Minting Company");
    		lblMintingCompany_1.setBounds(500, 230, 100, 16);
    		ViewEditCoin.add(lblMintingCompany_1);
     
    		eCompany = new JComboBox(cbCompany);
    		eCompany.setBounds(500, 255, 250, 20);
    		ViewEditCoin.add(eCompany);
     
    		// Second Tab: View/Edit - Coin List
    		JLabel lblCoinlist = new JLabel("Coin List");
    		lblCoinlist.setBounds(15, 50, 50, 14);
    		ViewEditCoin.add(lblCoinlist);
     
    		coinVec = c.getAllDetail();
     
    		eCoinList = new JList();
    		DefaultListModel listModel = new DefaultListModel();
     
    		//for (int i=0; i<(c.reTurnSize()); i++)
        	//	listModel.addElement(((Coin)coinVec.get(i)).getCoinName());
     
    		pos = eCoinList.getModel().getSize();
    		listModel.add(pos, coinName.getText());
     
    		eCoinList.setModel(listModel);
    		eCoinList.setSelectedIndex(0);
    		eCoinList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    		eCoinList.addListSelectionListener(new ListentityHandler()); 
     
    		listScrollPane = new JScrollPane();
    		listScrollPane.setBounds(15, 75, 125, 350);
    		listScrollPane.setViewportView(eCoinList);
     
    		ViewEditCoin.add(listScrollPane);
     
     
    		// Second Tab: View/Edit - Help Button
    		JButton button = new JButton("Help");
    		button.addActionListener(new HelpHandler());
    		button.setBounds(675, 400, 75, 25);
    		ViewEditCoin.add(button);
     
    		JButton btnViewImage = new JButton("View Image");
    		btnViewImage.setBounds(500, 332, 100, 25);
    		ViewEditCoin.add(btnViewImage);
    		btnViewImage.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {           
    				//add actionlistener and add Jlabel to display image 
     
    			}
    		});
     
    		JButton btnChangeImage = new JButton("Change Image");
    		btnChangeImage.setBounds(612, 332, 125, 25);
    		ViewEditCoin.add(btnChangeImage);
     
    	}
     
     
    	public BufferedImage rescale(BufferedImage originalImage)
        {
            BufferedImage resizedImage = new BufferedImage(baseSize, baseSize, BufferedImage.TYPE_INT_RGB);
            Graphics2D g = resizedImage.createGraphics();
            g.drawImage(originalImage, 0, 0, baseSize, baseSize, null);
            g.dispose();
            return resizedImage;
        }
     
     
    	 public void setTarget(File reference)
    	    {
    	        try {
    	            targetFile = reference;
    	            targetImg = rescale(ImageIO.read(reference));
    	        } catch (IOException e) {
    	            Logger.getLogger(LHCoinCatalogue.class.getName()).log(Level.SEVERE, null, e);
    	        }
     
    	       JLabel panel_1= new JLabel ();                       //Converted panel_1 into JLabel to support next line
    	        panel_1.setIcon(new ImageIcon(targetImg));          // *Caution*
    	    }
     
     
    	protected void ButtonViewActionPerformed( ActionEvent e) {
     
    	}
     
    	protected void browseButtonActionPerformed(ActionEvent e) {
     
    		JFileChooser fc = new JFileChooser(basePath);
            fc.setFileFilter(new JPEGImageFileFilter());
            int res = fc.showOpenDialog(null);
            // We have an image!
            try {
                if (res == JFileChooser.APPROVE_OPTION) {
                    File file = fc.getSelectedFile();
                    setTarget(file);
                } // Oops!
                else {
                    JOptionPane.showMessageDialog(null,
                            "You must select one image to be the reference.", "Aborting...",
                            JOptionPane.WARNING_MESSAGE);
                }
            } catch (Exception iOException) {
            }
     
     
    	}
     
     
    	// Listener
    	class AddHandler implements ActionListener
    	{
    		public void actionPerformed(ActionEvent e)
    		{	
    			System.out.println("[test output] Add button OK! [delete when needed.]");
     
    			int newCG = (int)coinGrade.getSelectedIndex();
    			int newCMT = (int)metalType.getSelectedIndex();
    			int newCom = (int)mintingCompany.getSelectedIndex();
     
    			String strWeight = coinWeight.getText();
    			String strYear = coinYear.getText();
    			String strcoinQuantity = coinQuantity.getText();
     
    			float iWeight = 0;
    			int iYear = 0;
    			int iQuantity = 0;
     
    			try {
    				iWeight = Float.parseFloat(strWeight);
    				iYear = Integer.parseInt(strYear);
    				iQuantity = Integer.parseInt(strcoinQuantity);
    				c.newCoinDetail(coinName.getText(), coinWeight.getText(), coinYear.getText(), coinCountry.getText(), coinQuantity.getText(), coinDescription.getText(), newCG, newCMT, newCom);
     
    			} catch (NumberFormatException nfe) {
    				JOptionPane.showMessageDialog( null,
    					"Please make sure the Weight, Year and Quantity must be fill with number.",
    					"Incorrect Input", JOptionPane.PLAIN_MESSAGE);
    			}
     
    			coinName.setText("");
    			coinWeight.setText("");
    			coinYear.setText(""); 
    			coinCountry.setText(""); 
    			coinQuantity.setText(""); 
    			coinDescription.setText("");
    		}
    	}
     
    	class EditHandler implements ActionListener
    	{
    		public void actionPerformed(ActionEvent e)
    		{
    			int newCG = (int)eCoinGrade.getSelectedIndex();
    			int newCMT = (int)eMetalType.getSelectedIndex();
    			int newCom = (int)eCompany.getSelectedIndex();
     
    			c.newCoinDetail(eCoinName.getText(), eCoinWeight.getText(), eCoinYear.getText(), eCountry.getText(), eQuantity.getText(), eDescription.getText(), newCG, newCMT, newCom);
     
    			System.out.println("[test output] Edit button OK! [delete when needed.]");
    		}
    	}
     
    	class DeleteHandler implements ActionListener
    	{
    		public void actionPerformed(ActionEvent e)
    		{
    			System.out.println("[test output] Delete button OK! [delete when needed.]");
     
     
    		}
    	}
     
    	class HelpHandler implements ActionListener
    	{
    		public void actionPerformed(ActionEvent e)
    		{
    			JOptionPane.showMessageDialog(helpFrame,"Test output");
    		}
    	}
     
    	class AddImageHandler implements ActionListener
    	{
    		public void actionPerformed(ActionEvent e)
    		{
    			System.out.println("[test output] Add Image button OK! [delete when needed.]");
    		}
    	}
     
    	class ListentityHandler implements ListSelectionListener
    	{
    		public void valueChanged(ListSelectionEvent arg0) {
    			bCoin = c.retrieveDetail(eCoinName.getText( ));
    			if (bCoin == false)
    			{	eCoinName.setText("Error: Testing output");	}
    			else
    			{	int selected = eCoinList.getSelectedIndex();
     
    				System.out.println("\n[test]Index Selected: " + (selected+1)+"[test]");
     
    				sName = c.reTurnName(eCoinName.getText());
    				eCoinName.setText(sName);
     
    				sWeight = c.reTurnWeight(eCoinWeight.getText( ));
    				eCoinWeight.setText(sWeight);	 
     
    				sYear = c.reTurnYear(eCoinYear.getText());
    				eCoinYear.setText(sYear);
     
    				sCountry = c.reTurnCountry(eCountry.getText());
    				eCountry.setText(sCountry);
     
    				sQuantity = c.reTurnQuantity(eQuantity.getText());
    				eQuantity.setText(sQuantity);
     
    				sDescription = c.reTurnDescription(eDescription.getText());
    				eDescription.setText(sDescription);
     
    				sGrade = c.reTurnCoinGrade(eCoinGrade.getSelectedIndex());
    				eCoinGrade.setSelectedIndex(sGrade);
     
    				sType = c.reTurnType(eMetalType.getSelectedIndex());
    				eMetalType.setSelectedIndex(sType);
     
    				sCompany = c.reTurnCompany(eCompany.getSelectedIndex());
    				eCompany.setSelectedIndex(sCompany);
     
    				System.out.println("[test]" + sName + "\t" + sWeight + "\t" +  sYear + "\t" +  sCountry  + "\t" + sQuantity  + "\n" + sDescription  + "\t" + sGrade  + "\t" + sType  + "\t" + sCompany +"[test]");
    				}
    		}
     
    	}
    }

    import java.util.Vector;
     
     
    class Controller {
     
    	private DataStorage ds;
    	private Coin ct;
    	private String rName;
     
    	private String all;
     
    	private String sName;
    	private String sWeight;
    	private String sYear;
    	private String sCountry;
    	private String sQuantity;
    	private String sDescription;
    	private int sGrade;
    	private int sType;
    	private int sCompany;
     
    	public Controller() 
    	{
    		ds = new DataStorage();
    	}
     
    	public void newCoinDetail(String newName, String newWeight, String newYear, String newCountry, String newQuantity, String newDescription, int newCoinGrade, int newCoinType, int newMintingCompany)
    	{
    		ds.newCoinDetail(new Coin(newName, Float.parseFloat(newWeight), Integer.parseInt(newYear), newCountry, Integer.parseInt(newQuantity), newDescription, newCoinGrade, newCoinType, newMintingCompany));
    		System.out.println("GUI -> Controller ok");
    	}	
     
    	public void EditDetail(String newName, String newWeight, String newYear, String newCountry, String newQuantity, String newDescription, int newCoinGrade, int newCoinType, int newMintingCompany)
    	{
    		ds.newCoinDetail(new Coin(newName, Float.parseFloat(newWeight), Integer.parseInt(newYear), newCountry, Integer.parseInt(newQuantity), newDescription, newCoinGrade, newCoinType, newMintingCompany));
    	}
     
    	public void removeCoinDetail(int selected)
    	{
    		ds.deleteDetail(selected);
    		System.out.println("[Test] Delete ok");
    	}
     
    	public Vector getAllDetail() {
        	return ds.getAllDetails();
        } 
     
    	public boolean retrieveDetail(String rName)
    	{
    		ct = ds.retrieveDetail(rName);
    		if (ct == null)
    			return false;
    		else
    			return true;
    	}	
     
     
    	// i dont know how to use the short method or (does it exist?).
    	public String reTurnName(String newName)
    	{	
    		System.out.println("[name]GUI <- Controller ok");
    		sName = ct.getCoinName();
    		return(sName);
     
    	}
     
    	public String reTurnWeight(String newWeight)
    	{
    		System.out.println("[Weight]GUI <- Controller ok");
    		sWeight = Float.toString(ct.getCoinWeight());
    		return(sWeight);
    	}
     
    	public String reTurnYear(String newYear)
    	{
    		System.out.println("[Year]GUI <- Controller ok");
    		sYear = Integer.toString(ct.getCoinYear());
    		return(sYear);
    	}
     
    	public String reTurnCountry(String newCountry)
    	{	
    		System.out.println("[Country]GUI <- Controller ok");
    		sCountry = ct.getCountry();
    		return(sCountry);
    	}
     
    	public String reTurnQuantity(String newQuantity)
    	{	
    		System.out.println("[Quantity]GUI <- Controller ok");
    		sQuantity = Integer.toString(ct.getQuantity());
    		return(sQuantity);
    	}
     
    	public String reTurnDescription(String newDescription)
    	{	
    		System.out.println("[Description]GUI <- Controller ok");
    		sDescription = ct.getDescription();
    		return(sDescription);
    	}
     
    	public int reTurnCoinGrade(int newGrade)
    	{	
    		System.out.println("[Grade]GUI <- Controller ok");
    		sGrade = ct.getCoinGrade();
    		return(sGrade);
    	}
     
    	public int reTurnType(int newType)
    	{	
    		System.out.println("[Type]GUI <- Controller ok");
    		sType = ct.getCoinType();
    		return(sType);
    	}
     
    	public int reTurnCompany(int newCompany)
    	{	
    		System.out.println("[Company]GUI <- Controller ok");
    		sCompany = ct.getMintingCompany();
    		return(sCompany);
    	}
     
    	public int reTurnSize()
    	{
    		int y = ds.returnSize();
    		return y;
    	}
    }

    import java.util.ArrayList;
    import java.util.Vector;
     
    class DataStorage {
     
    	private Vector CoinVec;
    	private Vector<Coin> storage = new Vector<Coin>();
     
    	public	DataStorage(){
    		CoinVec = new Vector();
    	}
     
    	public void newCoinDetail(Coin cDetail){	
    		CoinVec.addElement(cDetail);
     
    	}
     
    	public void deleteDetail(int selected){
    		CoinVec.remove(selected);
    	}
     
    	public void returnDetail(Coin cDetail){
    		CoinVec.contains(cDetail);
    	}
     
    	public Coin retrieveDetail(String cName){
    		Coin acc = null;
    		for (int i=0; i<CoinVec.size( ); i++)
    	{
    		acc = (Coin)CoinVec.get(i);
    		if (acc.getCoinName( ) == cName)
    			break;
    	}
    		return acc;
    	}
     
    	public void deleteDetail(Coin cDetail){
    		CoinVec.removeElement(cDetail);
    	}
     
    	public Vector getAllDetails() {
        	return CoinVec;
        }
     
    	public int returnSize()
    	{
    		int x = CoinVec.size();
    		return x;
    	}
     
    	public Coin[] retrieveMultipleCoins(String name) {
    		ArrayList<Coin> foundCoins = new ArrayList<Coin>();
     
    		for (int i = 0; i < this.storage.size(); i++) {
    			Coin temp = this.storage.get(i);
    			if (temp.getCoinName().equals(name)) {
    				foundCoins.add(temp);
    			}
    		}
     
    		Coin[] Coins = new Coin[foundCoins.size()];
    		foundCoins.toArray(Coins);
     
    		return Coins;
    	}
     
    	public Coin[] retrieveAllCoins() {
    		Coin[] Coins = new Coin[this.storage.size()];
     
    		for (int i = 0; i < this.storage.size(); i++) {
    			Coins[i] = this.storage.get(i);
    		}
     
    		return Coins;
    	}
    }

     
    class Coin {
     
    	private String coinName;
    	private float coinWeight;
    	private int	coinYear;
    	private String country;
    	private int	quantity;
    	private String description;
    	private int coinGrade;
    	private int coinType;
    	private int MintingCompany;
     
    	public Coin()
    	{
    		coinName = null;
    		coinWeight = 0;
    		coinYear = 0;
    		country = null;
    		quantity = 0;
    		description = null;
    		coinGrade = 0;
    		coinType = 0;
    		MintingCompany = 0;
    	}
     
    	public Coin(String cN, float cW, int cY, String cC, int qt, String cD, int cG, int cT, int cMC)
    	{
    		coinName = cN;
    		coinWeight = cW;
    		coinYear = cY;
    		country = cC;
    		quantity = qt;
    		description = cD;
    		coinGrade = cG;
    		coinType = cT;
    		MintingCompany = cMC;
    	}
     
    	public String getCoinName() {
    		return coinName;
    	}
     
    	public void setCoinName(String coinName) {
    		this.coinName = coinName;
    	}
     
    	public float getCoinWeight() {
    		return coinWeight;
    	}
     
    	public void setCoinWeight(float coinWeight) {
    		this.coinWeight = coinWeight;
    	}
     
    	public int getCoinYear() {
    		return coinYear;
    	}
     
    	public void setCoinYear(int coinYear) {
    		this.coinYear = coinYear;
    	}
     
    	public String getCountry() {
    		return country;
    	}
     
    	public void setCountry(String country) {
    		this.country = country;
    	}
     
    	public int getQuantity() {
    		return quantity;
    	}
     
    	public void setQuantity(int quantity) {
    		this.quantity = quantity;
    	}
     
    	public String getDescription() {
    		return description;
    	}
     
    	public void setDescription(String description) {
    		this.description = description;
    	}
     
    	public int getCoinGrade() {
    		return coinGrade;
    	}
     
    	public void setCoinGrade(int coinGrade) {
    		this.coinGrade = coinGrade;
    	}
     
    	public int getCoinType() {
    		return coinType;
    	}
     
    	public void setCoinType(int coinType) {
    		this.coinType = coinType;
    	}
     
    	public int getMintingCompany() {
    		return MintingCompany;
    	}
     
    	public void setMintingCompany(int mintingCompany) {
    		MintingCompany = mintingCompany;
    	}
     
    }
    Last edited by ErrorDC001; August 9th, 2014 at 08:32 AM.


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: [Please Help.] Adding values to JList

    You have posted a buttload of code and asked a rather open ended question. You get better help if you can ask a specific question and only post the code relevant to that question.
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Aug 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Re: [Please Help.] Adding values to JList

    sorry, i'm new to this forum. i thought it was appropriately to put everything. my question was how to add a values from Jtextfield/JtextArea to JList when i press a button.
    this example like:
    Untitled.jpg --> Untitled2.jpg

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: [Please Help.] Adding values to JList

    Have you added a listener to the button? If not, review the tutorial on adding an action listener. If you have and it's not working properly, then please point us to that code.

Tags for this Thread