Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: anyone a good java programmer?

  1. #1
    Banned
    Join Date
    Jan 2006
    Location
    Staines
    Posts
    4,945

    anyone a good java programmer?

    i need help!

  2. #2
    Banned
    Join Date
    Jan 2006
    Location
    Staines
    Posts
    4,945
    pleaseeeeeeeeeeee

  3. #3
    Goody 2 Puntos Coupe 20VT
    Join Date
    May 2007
    Location
    Guildford by way of Haddenham, Wilmslow and Rochdale (etc.)
    Posts
    6,399
    Quote Originally Posted by seaneyb View Post
    pleaseeeeeeeeeeee
    Oh go on then. You needn't beg!

    At the outset I have to say I haven't programmed Java, but I've been a Systems Programmer and faffed around with various languages over the years, perhaps I could help, within limits?

  4. #4
    Punto Lover
    Join Date
    Jan 2008
    Location
    Sutton, surrey
    Posts
    1,485
    whats up buddy? done a lil bit

  5. #5
    Southern Events Organiser
    Join Date
    Mar 2005
    Location
    eastbourne
    Posts
    8,816
    i did some at college, but dam that was a long time ago!

  6. #6
    Banned
    Join Date
    Jan 2006
    Location
    Staines
    Posts
    4,945
    haha well im on my second year at uni and this year we have the biggest twat ever as a teacher and hasnt taught us anything relevant to what we need to do for our assignment.

    Basically were asked to program a java address book. It is ment to be able to read in a txt file display it and run through the file and add, this is easy i just basically set it up to display in an arraylist and run through it.

    however im struggling with doing the delete function, it does delete but then im getting duplicate information from the txt file.

    i dont know if this works on this forum but heres my code

    Code:
    import java.util.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import java.io.*;
    
    import javax.swing.*;
    import java.awt.event.*;
    
    public class addressbook extends contact
    {
    	public JFrame frame;
    	public JButton btnadd, btndelete, btnsearch, btnprev, btnnext;
    	public JPanel panel;
    	public JTextField txtname, txtaddress, txthomeno, txtmobno;
    	public JLabel JlbName , JlbHtn, JlbMtn, JlbAddress;		
    	String storeName, storeAddress, storeHomePhone, storeMobilePhone; 
    
    	int index = 0;
    	ArrayList<contact> contactList = new ArrayList<contact>();
    	ArrayList<String> importingfile = new ArrayList<String>();
    	ArrayList<String> i = new ArrayList<String>();
    
    
    
    	public addressbook() {
    
    		//sets window
    		frame = new JFrame();
    		frame.setTitle("Address Book");
    		frame.setSize(800, 640);
    
    		//sets up panel
    		panel = new JPanel();
    		panel.setLayout(null);
    		frame.getContentPane().add(panel);
    
    		//Menu Bar
    		JMenuBar mb = new JMenuBar();
    		frame.setJMenuBar(mb);
    
    		JMenu file = new JMenu("File");
    		mb.add(file);
    		//Adds Exit to file menu bar and exits when clicked.
    
    		JMenuItem ReadFile = new JMenuItem("Read File");
    		file.add(ReadFile);
    		ReadFile.addActionListener(new ActionListener()
    		{public void actionPerformed(ActionEvent event) 
    		{
    			readContacts();
    			displayContact();
    		}
    		});
    
    		JMenuItem Clear = new JMenuItem("Clear Screen");
    		file.add(Clear);
    		Clear.addActionListener(new ActionListener()
    		{public void actionPerformed(ActionEvent event) 
    		{
    			clearfield();
    		}
    		});
    		JMenuItem exit = new JMenuItem("Exit");
    		file.add(exit);
    		exit.addActionListener(new ActionListener()
    		{public void actionPerformed(ActionEvent event) 
    		{
    			System.exit(0);
    		}
    		});
    
    		JMenu insert = new JMenu("Insert");
    		mb.add(insert);
    
    		JMenuItem imp = new JMenuItem("Import");
    		insert.add(imp);
    		imp.addActionListener(new ActionListener()
    		{public void actionPerformed(ActionEvent event)
    		{
    			//chooses file to open
    			JFileChooser fileopen = new JFileChooser();
    
    			int ret = fileopen.showDialog(null, "Open file");
    
    			if (ret == JFileChooser.APPROVE_OPTION) {
    				//File file = fileopen.getSelectedFile();
    				//for (String file : importingfile)
    				{
    					System.out.println("" + importingfile);
    				}
    
    			}
    		}
    		});
    
    		JMenuItem exp = new JMenuItem("Export");
    		insert.add(exp);
    		exp.addActionListener(new ActionListener()
    		{public void actionPerformed(ActionEvent event)
    		{
    			JFileChooser dialog = new JFileChooser();
    			dialog.setCurrentDirectory(new File("."));
    			dialog.setMultiSelectionEnabled(false);
    
    			dialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    			dialog.showSaveDialog(frame);
    			FileOutputStream  fileoutput = null;
    			FileInputStream fileinput = null;
    			String filename=null;
    
    			int temp;
    
    			try
    			{
    				filename = dialog.getSelectedFile().getPath();
    			}
    			catch(Exception e)
    			{
    			}
    
    			try
    			{
    				fileoutput = new FileOutputStream(filename +
    				"address.txt");
    			}
    			catch(Exception e)
    			{
    
    			}
    			try
    			{
    				fileinput = new FileInputStream("address.txt");
    			}
    			catch(Exception e)
    			{
    
    			}
    
    			try
    			{
    				do
    				{  temp = fileinput.read();
    				if(temp!=-1)
    					fileoutput.write(temp);
    				}while(temp!=-1);
    			}
    			catch(Exception e)
    			{
    
    			}
    		}
    
    		});
    
    
    		//Labels
    		JlbName = new JLabel("Name:");
    		JlbName.setBounds(10, 50, 100, 20);
    		panel.add(JlbName);
    
    		JlbHtn = new JLabel("Home Number:");
    		JlbHtn.setBounds(10, 90, 150, 20);
    		panel.add(JlbHtn);
    
    		JlbMtn = new JLabel("Mobile Number:");
    		JlbMtn.setBounds(10, 130, 200, 20);
    		panel.add(JlbMtn);
    
    		JlbAddress = new JLabel("Address:");
    		JlbAddress.setBounds(10, 170, 250, 20);
    		panel.add(JlbAddress);
    
    		//Text Fields
    		txtname = new JTextField("");
    		txtname.setBounds(120, 50, 200, 20);
    		panel.add(txtname);
    
    		txthomeno = new JTextField("");
    		txthomeno.setBounds(120, 90, 200, 20);
    		panel.add(txthomeno);
    
    		txtmobno = new JTextField("");
    		txtmobno.setBounds(120, 130, 200, 20);
    		panel.add(txtmobno);
    
    		txtaddress = new JTextField("");
    		txtaddress.setBounds(120, 170, 250, 20);
    		panel.add(txtaddress);
    
    
    
    
    		//Buttons && Button Functions
    		btnadd = new JButton("Add");
    		btnadd.setBounds(10, 250, 65, 50);
    		btnadd.addActionListener(new ActionListener()
    		{public void actionPerformed(ActionEvent event)
    		{
    			addContacts();
    		}
    		});
    		panel.add(btnadd);
    
    		btndelete = new JButton("Delete");
    		btndelete.setBounds(80, 250, 65, 50);
    		btndelete.addActionListener(new ActionListener()
    		{public void actionPerformed(ActionEvent event)
    		{
    			deletecontact();
    		}
    		});
    		panel.add(btndelete);
    
    		btnsearch = new JButton("Search");
    		btnsearch.setBounds(150, 250, 65, 50);
    		btnsearch.addActionListener(new ActionListener()
    		{public void actionPerformed(ActionEvent event)
    		{
    			searchContacts();	
    		}});
    		panel.add(btnsearch);
    
    		btnprev = new JButton("Prev");
    		btnprev.setBounds(60, 400, 65, 50);
    		btnprev.addActionListener(new ActionListener()
    		{public void actionPerformed(ActionEvent event)
    		{
    			index--;   
    			readContacts();
    			displayContact();
    
    		}});
    		panel.add(btnprev);
    
    		btnnext = new JButton("Next");
    		btnnext.setBounds(60, 450, 65, 50);
    		btnnext.addActionListener(new ActionListener()
    		{public void actionPerformed(ActionEvent event)
    		{
    			index++;	
    			readContacts();
    			displayContact();
    
    		}});
    		panel.add(btnnext);
    
    		frame.setVisible(true);
    		panel.setVisible(true);
    	}
    	public void displayContact()
    	{
    		contact c = contactList.get(index);
    
    		txtname.setText (c.getName());
    		txtaddress.setText (c.getAddress());
    		txthomeno.setText(c.getTelephone());
    		txtmobno.setText(c.getMobile());
    	} 
    	public void clearfield()
    	{
    		txtname.setText("");
    		txtaddress.setText("");
    		txthomeno.setText("");
    		txtmobno.setText("");
    	}
    	public void deletecontact()
    	{
    		{
    			FileOutputStream fileoutput = null;
    
    			contactList.remove(index);
    			System.out.println(contactList);
    
    			txtname.setText("");
    			txtaddress.setText("");
    			txthomeno.setText("");
    			txtmobno.setText("");
    
    			try {
    
    				fileoutput = new FileOutputStream("address1.buab");
    
    			} catch (FileNotFoundException ex)
    			{
    				Logger.getLogger(addressbook.class.getName()).log(Level.SEVERE, null, ex);
    
    			}
    
    
    			for (contact c : contactList)
    
    			{
    				PrintStream p = new PrintStream(fileoutput);
    				contact temp = c;
    				p.println(temp.getName());
    				p.println(temp.getTelephone());
    				p.println(temp.getMobile());
    				p.println(temp.getAddress());
    			}
    		}} 	
    
    	public void searchContacts(){}
    
    	public void addContacts()
    
    	{
    		try {
    			ArrayList<String> Contacts = new ArrayList<String>();
    
    
    			storeName = txtname.getText();
    			storeAddress = txtaddress.getText();
    			storeHomePhone = txthomeno.getText();
    			storeMobilePhone = txtmobno.getText();
    
    			Contacts.add(storeName);
    			Contacts.add(storeHomePhone);
    			Contacts.add(storeMobilePhone);
    			Contacts.add(storeAddress);
    
    			System.out.println(Contacts);
    
    
    			BufferedWriter out = new BufferedWriter(new FileWriter("address.txt",true));
    
    			for(String writeToFile : Contacts){
    				out.write(writeToFile);
    				out.newLine();
    				out.write(" ");
    
    			}
    			out.close();   
    		} catch (IOException ex) {
    
    			System.err.println("ERROR:" + ex);
    		}
    
    	}
    
    	public void readContacts()
    	{
    		try {
    			BufferedReader file_in = new BufferedReader(new FileReader(
    			"address.txt"));
    
    			String name = "", address = "", telephone = "", mobile = "";
    			int counter = 0;
    			while (true) {
    				String line = file_in.readLine();
    				if (line == null)
    					break;
    				counter++;
    				if (counter == 1) {
    					name = line;
    				} else if (counter == 2) {
    					address = line;
    				} else if (counter == 3) {
    					telephone = line;
    				} else if (counter == 4) {
    					mobile = line;
    					contact c = new contact(name, address, telephone, mobile);
    					contactList.add(c);
    					counter = 0;
    				}
    
    			}
    		} catch (Exception e1) {
    			JOptionPane.showMessageDialog(null, "File Not Found",
    					"File Not Found", JOptionPane.ERROR_MESSAGE);
    		}
    
    	} 
    
    
    	public static void main(String[] args) {
    		new addressbook();
    	}
    
    }
    address.txt contains this below

    Tony Hancock
    01202719029
    07676101393
    1 Charminster Road, Bournemouth, Dorset, BH8 8UE
    Father Christmas
    +3581938292971
    +3587721982917
    HQ, Lapland, Finland, SAN TA1
    Elizabeth Windsor
    0207777777
    0783598378
    1, The Mall, London

  7. #7
    Goody 2 Puntos Coupe 20VT
    Join Date
    May 2007
    Location
    Guildford by way of Haddenham, Wilmslow and Rochdale (etc.)
    Posts
    6,399
    Just a quick observation:

    You're using buffered file I/O, but I don't see any "flush" function usage to ensure that changes have been fully written to disk. This may be incorporated into the "close" function but I'm not familiar with the precise Java function library details.

    In AddContacts(), what is the intended purpose of the line 'out.write(" ");'? This doesn't seem to serve any sensible purpose. It could also negate your test for a "null" line on input.

    As said, I'm not familiar with Java per se, so I may be misled, but I've been debugging programs in various languages for years.

    HTTH and Cheers, Tim

  8. #8
    Goody 2 Puntos Coupe 20VT
    Join Date
    May 2007
    Location
    Guildford by way of Haddenham, Wilmslow and Rochdale (etc.)
    Posts
    6,399
    Quote Originally Posted by seaneyb View Post
    haha well im on my second year at uni and this year we have the biggest twat ever as a teacher and hasnt taught us anything relevant to what we need to do for our assignment.
    Been there, got bitten by the failings of the University system's courses and their lack of realistic goals and methods. I quit after my 2nd year 'cos my course was so far removed from the practical needs of industry as to be useless. I went and learned "on the job" after some basic but targeted training from IBM. I hope the Universities are not still including such irrelevancies as "programming language design" and "numerical analysis" in IT courses these days.

  9. #9
    Banned
    Join Date
    Jan 2006
    Location
    Staines
    Posts
    4,945
    Quote Originally Posted by GT3guy View Post
    Just a quick observation:

    You're using buffered file I/O, but I don't see any "flush" function usage to ensure that changes have been fully written to disk. This may be incorporated into the "close" function but I'm not familiar with the precise Java function library details.

    In AddContacts(), what is the intended purpose of the line 'out.write(" ");'? This doesn't seem to serve any sensible purpose. It could also negate your test for a "null" line on input.

    As said, I'm not familiar with Java per se, so I may be misled, but I've been debugging programs in various languages for years.

    HTTH and Cheers, Tim
    the out.write(""); line basically adds another line to the text file thats blank so if i want to add another person it will display it on that line, its simply just for formatting so the program can read it thats all.


    for the buffered reader thats why im using a try catch method to make sure it writes thats javas "flush" function.


    This isnt the problem its the deletecontacts() method thats causing the problems.

  10. #10
    Banned
    Join Date
    Jan 2006
    Location
    Staines
    Posts
    4,945
    Quote Originally Posted by GT3guy View Post
    Been there, got bitten by the failings of the University system's courses and their lack of realistic goals and methods. I quit after my 2nd year 'cos my course was so far removed from the practical needs of industry as to be useless. I went and learned "on the job" after some basic but targeted training from IBM. I hope the Universities are not still including such irrelevancies as "programming language design" and "numerical analysis" in IT courses these days.
    yeah man i have 2 **** lecturers this year last year was amazing had the most helpful lectueres ever but only 1 of them are on the second year .

    Im now reverting to buying a java book to try and get me through the next 2 years!

    haha well on my 2nd year im doing programming systems design networking business studys and data management

    first year was networks systems design programming web and media business and data management.

    its a pretty good course just need the right lecturers!

Page 1 of 3 123 LastLast

Similar Threads

  1. java programming
    By seaneyb in forum Technobabble
    Replies: 4
    Last Post: 10th February 2009, 00:33
  2. Java scripting
    By Mawbster in forum Technobabble
    Replies: 8
    Last Post: 9th January 2007, 15:13
  3. What Is This? Java 2 Platform Standard Edition
    By soche in forum Technobabble
    Replies: 1
    Last Post: 14th March 2005, 22:44
  4. Java mobile games
    By joey_turbo in forum Technobabble
    Replies: 2
    Last Post: 26th January 2005, 23:00
  5. Free Java games
    By joey_turbo in forum Technobabble
    Replies: 0
    Last Post: 20th October 2004, 13:01

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •