Hi, I've got an error message on "public static void save_data" and "public static void retrieve_data". Please help, thanks

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class face1 extends JFrame
implements ActionListener

{
JPanel pm,menup,fp,f1p,f2p,f3p,f4p,f5p,pf_1,pf_2,pf_3,pf_4,pf_5;
static String f1[] = new String[2];
static String f2[] = new String[2];
static String f3[] = new String[2];
static String f4[] = new String[2];
static String f5[] = new String[2];
	static int count = 0;
JLabel logo,m,f1,f2,f3,f4,f5,j_f1,j_f2,j_f3,j_f4,j_f5,jf_1d,jf_2d,jf_3d,jf_4d,jf_5d,j_space01;
JButton face,eyes,lips,campaign,mlogin,reg,addb,refresh;
JTextField t_f1,t_f2,t_f3,t_f4,t_f5;
ImageIcon fa1,fa2,fa3,fa4,fa5,wall;
reg f;
ml g;
face a;
JScrollPane jScroll;

              public face1()
                           {
super("Face | Princezz");

try 
	{
	retrieve_data();
	}
	catch(Exception e){};

pm = new JPanel();
menup = new JPanel();

fp = new JPanel();
pf_1 = new JPanel();
pf_2 = new JPanel();
pf_3 = new JPanel();
pf_4 = new JPanel();
pf_5 = new JPanel();
f1p = new JPanel();
f2p = new JPanel();
f3p = new JPanel();	
f4p = new JPanel();	
f5p = new JPanel();	

pm.setLayout(new FlowLayout());
pm.setBackground(Color.black);

menup.setLayout(new GridLayout(1,0));
menup.setBackground(Color.black);


fp.setLayout(new GridLayout(1,0));     
fp.setBackground(Color.black);

pf_1.setLayout(new GridLayout(0,1));
pf_1.setBackground(Color.black);

pf_2.setLayout(new GridLayout(0,1));
pf_2.setBackground(Color.black);

pf_3.setLayout(new GridLayout(0,1));
pf_3.setBackground(Color.black);

pf_4.setLayout(new GridLayout(0,1));
pf_4.setBackground(Color.black);

pf_5.setLayout(new GridLayout(0,1));
pf_5.setBackground(Color.black);

f1p.setLayout(new FlowLayout());
f1p.setBackground(Color.black);

f2p.setLayout(new FlowLayout());
f2p.setBackground(Color.black);

f3p.setLayout(new FlowLayout());
f3p.setBackground(Color.black);

f4p.setLayout(new FlowLayout());
f4p.setBackground(Color.black);

f5p.setLayout(new FlowLayout());
f5p.setBackground(Color.black);

j_space01 = new JLabel("    ");
j_space01.setForeground(Color.black);

JLabel logo = new JLabel("Princezz",JLabel.CENTER);
logo.setForeground(Color.pink);
logo.setFont(new Font("Bradley Hand ITC",Font.ITALIC,33));

face= new JButton ("FACE");
face.setBackground(Color.pink);
face.setForeground(Color.white);
face.setContentAreaFilled(true);
face.setFocusPainted(false);
java.awt.Font font0 = new java.awt.Font("Times New Roman",Font.BOLD,12);
face.setFont(font0);
getContentPane().add(face);

eyes= new JButton("EYES");
eyes.setBackground(Color.black);
eyes.setForeground(Color.white); 
eyes.setContentAreaFilled(false);
eyes.setFocusPainted(false);
java.awt.Font font1 = new java.awt.Font("Times New Roman",Font.BOLD,12);
eyes.setFont(font1);
eyes.addActionListener(this);
getContentPane().add(eyes);

lips= new JButton("LIPS");
lips.setBackground(Color.black);
lips.setForeground(Color.white);
lips.setContentAreaFilled(false);
lips.setFocusPainted(false);
java.awt.Font font2 = new java.awt.Font("Times New Roman",Font.BOLD,12);
lips.setFont(font2);
lips.addActionListener(this);
getContentPane().add(lips);

campaign= new JButton("CAMPAIGN");
campaign.setBackground(Color.black);
campaign.setForeground(Color.white);
campaign.setContentAreaFilled(false);
campaign.setFocusPainted(false);
java.awt.Font font3 = new java.awt.Font("Times New Roman",Font.BOLD,12);
campaign.setFont(font3);
campaign.addActionListener(this);
getContentPane().add(campaign);

mlogin = new JButton("Login   |  ");
mlogin.setBackground(Color.black);
mlogin.setForeground(Color.pink);
mlogin.setBorderPainted(false);
mlogin.setContentAreaFilled(false);
mlogin.setFocusPainted(false);
java.awt.Font font4 = new java.awt.Font("Times New Roman",Font.BOLD,14);
mlogin.setFont(font4);
mlogin.addActionListener(this);
getContentPane().add(mlogin, "East");

reg = new JButton("Join Us");
reg.setBackground(Color.black);
reg.setForeground(Color.pink);
reg.setBorderPainted(false);
reg.setContentAreaFilled(false);
reg.setFocusPainted(false);
java.awt.Font font5 = new java.awt.Font("Times New Roman",Font.BOLD,14);
reg.setFont(font5);
reg.addActionListener(this);
getContentPane().add(reg);

addb = new JButton("Add to cart");
java.awt.Font font6 = new java.awt.Font("Times New Roman",Font.BOLD,10);
addb.setFont(font6);
addb.addActionListener(this);
getContentPane().add(addb);

refresh = new JButton("Refresh");
java.awt.Font font7 = new java.awt.Font("Times New Roman",Font.BOLD,10);
refresh.setFont(font7);
refresh.addActionListener(this);
getContentPane().add(refresh);

ImageIcon fa1 = new ImageIcon("f1.jpg");
JLabel f1 = new JLabel(fa1);

ImageIcon fa2 = new ImageIcon("f2.jpg");
JLabel f2 = new JLabel(fa2);

ImageIcon fa3 = new ImageIcon("f3.jpg");
JLabel f3 = new JLabel(fa3);

ImageIcon fa4 = new ImageIcon("f4.jpg");
JLabel f4 = new JLabel(fa4);

ImageIcon fa5 = new ImageIcon("f5.jpg");
JLabel f5 = new JLabel(fa5);

jf_1d = new JLabel("2-way face foundation / S$25",JLabel.CENTER);
jf_1d.setForeground(Color.white);
java.awt.Font font8 = new java.awt.Font("Arial",Font.BOLD,12);
jf_1d.setFont(font8);

jf_2d = new JLabel("Oil free beige foundation / S$15",JLabel.CENTER);
jf_2d.setForeground(Color.white);
java.awt.Font font9 = new java.awt.Font("Arial",Font.BOLD,12);
jf_2d.setFont(font9);

jf_3d = new JLabel("Water cream foundation / S$30",JLabel.CENTER);
jf_3d.setForeground(Color.white);
java.awt.Font font10 = new java.awt.Font("Arial",Font.BOLD,12);
jf_3d.setFont(font10);

jf_4d = new JLabel("Basic Powder / S$12",JLabel.CENTER);
jf_4d.setForeground(Color.white);
java.awt.Font font11 = new java.awt.Font("Arial",Font.BOLD,12);
jf_4d.setFont(font11);

jf_5d = new JLabel("Loose Powder / S$17",JLabel.CENTER);
jf_5d.setForeground(Color.white);
java.awt.Font font12 = new java.awt.Font("Arial",Font.BOLD,12);
jf_5d.setFont(font12);


j_f1 = new JLabel("Quantity:");
j_f1.setForeground(Color.white);
java.awt.Font font13 = new java.awt.Font("Arial",Font.BOLD,10);
j_f1.setFont(font13);

j_f2 = new JLabel("Quantity:");
j_f2.setForeground(Color.white);
java.awt.Font font14 = new java.awt.Font("Arial",Font.BOLD,10);
j_f2.setFont(font14);

j_f3 = new JLabel("Quantity:");
j_f3.setForeground(Color.white);
java.awt.Font font15 = new java.awt.Font("Arial",Font.BOLD,10);
j_f3.setFont(font15);

j_f4 = new JLabel("Quantity:");
j_f4.setForeground(Color.white);
java.awt.Font font16 = new java.awt.Font("Arial",Font.BOLD,10);
j_f4.setFont(font16);

j_f5 = new JLabel("Quantity:");
j_f5.setForeground(Color.white);
java.awt.Font font17 = new java.awt.Font("Arial",Font.BOLD,10);
j_f5.setFont(font17);

t_f1 = new JTextField(2);
t_f2 = new JTextField(2);
t_f3 = new JTextField(2);
t_f4 = new JTextField(2);
t_f5 = new JTextField(2);

f1p.add(j_f1); 
f1p.add(t_f1);

f2p.add(j_f2); 
f2p.add(t_f2);

f3p.add(j_f3); 
f3p.add(t_f3);

f4p.add(j_f4); 
f4p.add(t_f4);

f5p.add(j_f5); 
f5p.add(t_f5);
f5p.add(addb);
f5p.add(refresh);

menup.add(logo);
menup.add(j_space01);
menup.add(face);
menup.add(eyes);
menup.add(lips);
menup.add(campaign);
menup.add(mlogin);
menup.add(reg);

pm.add(menup);

pf_1.add(f1);
pf_1.add(jf_1d);
pf_1.add(f1p);

pf_2.add(f2);
pf_2.add(jf_2d);
pf_2.add(f2p);

pf_3.add(f3);
pf_3.add(jf_3d);
pf_3.add(f3p);

pf_4.add(f4);
pf_4.add(jf_4d);
pf_4.add(f4p);

pf_5.add(f5);
pf_5.add(jf_5d);
pf_5.add(f5p);

fp.add(pf_1);
fp.add(pf_2);
fp.add(pf_3);
fp.add(pf_4);
fp.add(pf_5);

jScroll = new JScrollPane(fp);
jScroll.setBackground(Color.red);
getContentPane().add(jScroll);
 
getContentPane().add(pm,"North");
getContentPane().add(fp);

setSize(1000,700);
setVisible(true);

}

public void actionPerformed(ActionEvent e) {

if(e.getSource() == reg)
f =  new reg();
this.hide();

if(e.getSource() == mlogin)
g =  new ml();
this.hide();


{
		if(e.getSource() == refresh)
		{
			/*face a = new face();
			this.hide();*/
		try{
			save_data();

		}catch(Exception da){};		

		}
		
		if(e.getSource() == addb)
		{
			f1[count] = t_f1.getText();
			f2[count] = t_f2.getText();
			f3[count] = t_f3.getText();
			f4[count] = t_f4.getText();
			f5[count] = t_f5.getText();
			count ++;
		}
	}

	public static void save_data() throws Exception
	{
		RandomAccessFile fo = new RandomAccessFile("forder.dat","rw");
		fo.writeInt(count);
			for(int x = 0; x <count; x++)
			{
				info.writeUTF(f1[x]);
				info.writeUTF(f2[x]);
				info.writeUTF(f3[x]);
				info.writeUTF(f4[x]);
				info.writeUTF(f5[x]);
			}
	}

	public static void retrieve_data() throws Exception
	{
		RandomAccessFile fo = new RandomAccessFile("forder.dat","rw");
		count = fo.readInt();
			for(int x = 0; x <count; x++)
			{
				f1[x] = info.readUTF();
				f2[x]= info.readUTF();
				f3[x] = info.readUTF();
				f4[x] = info.readUTF();
				f5[x] = info.readUTF();
			}
	}

}
                    
public static void main(String args[])
	{
face1 x = new face1();
	}  
}

Recommended Answers

All 3 Replies

you are creating methods within methods.
chech your opening and closing brackets ({})

Thx for the prompt reply.

Can you help me solve this error? Once... Thx
I just dont know how..

Newbie..

well, for each opening bracket { you must have a closing bracket, closing that particular block }

if you look at the next part of your code above:

public void actionPerformed(ActionEvent e) {
 
if(e.getSource() == reg)
f =  new reg();
this.hide();
 
if(e.getSource() == mlogin)
g =  new ml();
this.hide();
 
 
{ // open this block
		if(e.getSource() == refresh)
		{
			/*face a = new face();
			this.hide();*/
		try{
			save_data();
 
		}catch(Exception da){};		
 
		}
 
		if(e.getSource() == addb)
		{
			f1[count] = t_f1.getText();
			f2[count] = t_f2.getText();
			f3[count] = t_f3.getText();
			f4[count] = t_f4.getText();
			f5[count] = t_f5.getText();
			count ++;
		}
	} // close this block
 
	public static void save_data() throws Exception

I added a few comments to show you what block you 're actually closing.
you haven't closed your actionPerformed method yet, before you create your other methods, they are defined within that method.

so, try adding a closing bracket before you start that save_data method
and remove one at the end of your class.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.