Title: Beat it Game
Description: this is a game named as Beat it in which you have to reduce the number of overall balls in this you can create your own games and share them with your friends it also has a mp3 plyer by which you can play songs from it.
import javax.swing.*;
import java.applet.*;
import java.awt.event.*;
import java.net.*;
import java.awt.*;
import java.io.*;
import java.awt.event.*;
public class player extends JFrame implements MouseListener, ActionListener
{
private JLabel tile[],status_bar;
private ImageIcon tile_img[];
private Container c;
private int max_tile=99;
private JMenuItem new_f,open_f,save_f,exit_f,hint_f,editor_t,mp3_t;
private int mp=0,mr=0,m=0,total_ball=0,total_tile=0;
private boolean status=false;
private int w=50,h=55;
private JPanel panel;
private AudioClip drag,drop;
private URL drag_url,drop_url;
private String text;
private int mp_pos=0;
public player()
{
text=new String("Beat it");
File drag_f=new File("drag.wav");
File drop_f=new File("drop.wav");
try
{
drag_url=drag_f.toURL ();
drop_url=drop_f.toURL ();
System.out.println ("in try");
}
catch(MalformedURLException mfe)
{
System.out.println ("in mfe");
}
//System.out.println (drag_url.getPath ());
drag=Applet.newAudioClip(drag_url);
drop=Applet.newAudioClip (drop_url);
c=getContentPane();
status_bar=new JLabel();
tile_img=new ImageIcon[3];
tile_img[0]=null;
tile_img[1]=new ImageIcon("tile1.jpg");
tile_img[2]=new ImageIcon("tile&ball1.jpg");
ImageIcon beat_it=new ImageIcon("beat_it.ico");
tile=new JLabel[max_tile];
panel=new JPanel();
panel.setLayout (null);
for(int i=0;i
tile[i]=new JLabel();
tile[i].addMouseListener (this);
tile[i].setSize (w,h);
}
int count=1,lx=20,ly=5;
for(int i=0;i
tile[i].setLocation (lx,ly);
lx+=w;
if(count%11==0)
{
ly+=h;
lx=20;
}
panel.add (tile[i]);
count++;
}
c.add (panel,BorderLayout.CENTER);
c.add (status_bar,BorderLayout.SOUTH);
JMenu file=new JMenu("File");
JMenu tool=new JMenu("Tools");
new_f= new JMenuItem("New");
open_f=new JMenuItem("Open...");
save_f=new JMenuItem("Save...");
hint_f=new JMenuItem("Hint...");
exit_f=new JMenuItem("Exit");
editor_t=new JMenuItem("Game Editor");
mp3_t=new JMenuItem("MP3 Player");
mp3_t.addActionListener (this);
editor_t.addActionListener (this);
new_f.addActionListener (this);
open_f.addActionListener (this);
save_f.addActionListener (this);
hint_f.addActionListener (this);
exit_f.addActionListener (this);
file.add (new_f);;
file.add (open_f);
file.add (save_f);
file.add (hint_f);
file.add (exit_f);
tool.add (editor_t);
tool.add (mp3_t);
JMenuBar bar=new JMenuBar();
bar.add (file);
bar.add(tool);
super.setJMenuBar (bar);
super.setBounds(25,25,600,650);
super.setResizable (false);
super.setVisible (true);
super.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
File f=new File("games/default.game");
read_game(f);
super.setTitle (text+" "+f.getName ());
}
public static void main(String a[])
{
player mainframe=new player();
}
public void mouseClicked (MouseEvent e)
{
// TODO: Add your code here
}
public void mousePressed (MouseEvent e)
{}
public void mouseReleased(MouseEvent e)
{
for(int i=0;i
tile[i].setBorder (null);
}
JLabel temp=new JLabel();
temp=(JLabel)e.getSource ();
if(status==false)
{
drag.play ();
for(int i=0;i
if(tile[i]==temp )
{
mp=i;
status=true;
super.setCursor (Cursor.getPredefinedCursor (Cursor.HAND_CURSOR));
break;
}
}
System.out.println("index pressed=:\t"+mp);
return;
}
if(status==true && tile[mp].getIcon ()==tile_img[2])
{
System.out.println("status true");;
for(int i=0;i
if(tile[i]==temp )
{
mr=i;
break;
}
}
if(tile[mr].getIcon ()==tile_img[1])
{
if(tile[mp].getX ()==tile[mr].getX ())
{
if((tile[mr].getY ()>tile[mp].getY()) && (tile[mp+11].getIcon ()==tile_img[2]) && (tile[mr]==tile[mp+22]) )
{
tile[mp+11].setIcon (tile_img[1]);
tile[mp].setIcon (tile_img[1]);
tile[mr].setIcon (tile_img[2]);
total_ball--;
drop.play ();
}
if((tile[mr].getY ()
tile[mp-11].setIcon (tile_img[1]);
tile[mp].setIcon (tile_img[1]);
tile[mr].setIcon (tile_img[2]);
total_ball--;
drop.play ();
}
}
if(tile[mp].getY()==tile[mr].getY ())
{
if((tile[mr].getX ()>tile[mp].getX()) && (tile[mp+1].getIcon ()==tile_img[2])&& (tile[mr]==tile[mp+2]))
{
tile[mp+1].setIcon (tile_img[1]);
tile[mp].setIcon (tile_img[1]);
tile[mr].setIcon (tile_img[2]);
total_ball--;
drop.play ();
}
if((tile[mr].getX ()
tile[mp-1].setIcon (tile_img[1]);
tile[mp].setIcon (tile_img[1]);
tile[mr].setIcon (tile_img[2]);
total_ball--;
drop.play ();
}
}
super.setCursor (Cursor.getPredefinedCursor (Cursor.DEFAULT_CURSOR));
}
System.out.println("index released=:\t"+mr);
check();
status=false;
}
if(status==true && tile[mp].getIcon ()==tile_img[1])
{
status=false;
super.setCursor (Cursor.getPredefinedCursor (Cursor.DEFAULT_CURSOR));
}
status_bar.setText (" Balls left "+total_ball);
}
public void mouseEntered (MouseEvent e)
{
// TODO: Add your code here
}
public void mouseExited (MouseEvent e)
{
// TODO: Add your code here
}
public void actionPerformed (ActionEvent e)
{
if((JMenuItem)e.getSource ()==new_f)
{
System.out.println("in new_f event");
new_d();
}
if((JMenuItem)e.getSource ()==open_f)
{
System.out.println("in open_f event");
open();
}
if((JMenuItem)e.getSource ()==save_f)
{
System.out.println("in save_f event");
save();
}
if((JMenuItem)e.getSource ()==hint_f)
{
System.out.println("in save_f event");
hint();
}
if((JMenuItem)e.getSource ()==exit_f)
{
System.out.println("in exit_f event");
super.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
super.dispose();
}
if((JMenuItem)e.getSource ()==editor_t)
{
System.out.println("in editor_t event");
editor editor=new editor();
}
if((JMenuItem)e.getSource ()==mp3_t)
{
System.out.println("in mp3_t event");
mp3 mp3=new mp3();
}
}
public void new_d()
{
JFileChooser fc=new JFileChooser("C:ksm/beat_it/games");
fc.setFileSelectionMode (JFileChooser.FILES_ONLY);
filter filter=new filter("game");
fc.addChoosableFileFilter (filter);
int result=fc.showOpenDialog (open_f);
if(result==JFileChooser.APPROVE_OPTION)
{
File f=fc.getSelectedFile ();
if(f.exists ()==true && f.isFile ()==true)
{
read_game(f);
super.setTitle (text+" "+f.getName ());
}
else
JOptionPane.showMessageDialog (this,"invalid file selected","Invalid File",
JOptionPane.ERROR_MESSAGE);
}
}
public void open()
{
JFileChooser fc=new JFileChooser("C:ksm/beat_it/games");
fc.setFileSelectionMode (JFileChooser.FILES_ONLY);
filter filter=new filter("sav");
fc.addChoosableFileFilter (filter);
int result=fc.showOpenDialog (open_f);
if(result==JFileChooser.APPROVE_OPTION)
{
File f=fc.getSelectedFile ();
if(f.exists ()==true && f.isFile ()==true)
{
read(f);
super.setTitle (text+" "+f.getName ());
}
else
JOptionPane.showMessageDialog (this,"invalid file selected","Invalid File",
JOptionPane.ERROR_MESSAGE);
}
}
public void save()
{
JFileChooser fc=new JFileChooser("C:ksm/beat_it/games");
fc.setFileSelectionMode (JFileChooser.FILES_ONLY);
filter filter=new filter("sav");
fc.addChoosableFileFilter (filter);
int result=fc.showSaveDialog (open_f);
if(result==JFileChooser.APPROVE_OPTION)
{
File fs=fc.getSelectedFile ();
String temp=new String(fs.getPath ());
temp+=".sav";
File f=new File(temp);
super.setTitle (text+""+f.getName ());
write(f);
}
}
public void read_game(File fi)
{
try
{
//File f=new File("c:/ksm/temp11.game");
File f=new File(fi.getAbsolutePath ());
System.out.println("file selected:\t"+f);
FileInputStream fis=new FileInputStream(f);
DataInputStream dis=new DataInputStream(fis);
byte image_status=0;
if(dis.readInt ()==30139)
{
for(int i=0;i
image_status=dis.readByte ();
tile[i].setIcon (tile_img[image_status]);
if(tile[i].getIcon ()==tile_img[1])
{
total_tile++;
}
if(tile[i].getIcon ()==tile_img[2])
{
total_ball++;
}
}
}
else
{
JOptionPane.showMessageDialog (this,"The File: "+fi.getName ()+" \nyou selected is not correct" ,"Incorrect File",JOptionPane.ERROR_MESSAGE);
}
dis.close ();
status_bar.setText ("Total Balls "+total_ball);
}
catch(IOException ioe)
{}
}
public void read(File fi)
{
try
{
//File f=new File("c:/ksm/temp11.game");
File f=new File(fi.getAbsolutePath ());
System.out.println("file selected:\t"+f);
FileInputStream fis=new FileInputStream(f);
DataInputStream dis=new DataInputStream(fis);
byte image_status=0;
if(dis.readInt ()==19100)
{
for(int i=0;i
image_status=dis.readByte ();
tile[i].setIcon (tile_img[image_status]);
if(tile[i].getIcon ()==tile_img[1])
{
total_tile++;
}
if(tile[i].getIcon ()==tile_img[2])
{
total_ball++;
}
}
}
else
{
JOptionPane.showMessageDialog (this,"The File: "+fi.getName ()+" \nyou selected is not correct" ,"Incorrect File",JOptionPane.ERROR_MESSAGE);
}
dis.close ();
status_bar.setText ("Total Balls "+total_ball);
}
catch(IOException ioe)
{}
}
public void write(File fi)
{
try
{
//File f=new File("c:/ksm/temp11.game");
File f=new File(fi.getAbsolutePath ());
System.out.println("file selected:\t"+f);
FileOutputStream fos=new FileOutputStream(f);
DataOutputStream dos=new DataOutputStream(fos);
dos.writeInt (19100);
for(int i=0;i
if(tile[i].getIcon ()==tile_img[1])
dos.writeByte(1);
else if(tile[i].getIcon ()==tile_img[2])
dos.writeByte (2);
else if(tile[i].getIcon ()==tile_img[0])
dos.writeByte(0);
}
dos.flush ();
dos.close ();
}
catch(IOException ioe)
{}
}
public void check()
{
boolean find=false;
for(mp=0;mp
if(tile[mp].getIcon ()==tile_img[2])
if(tile[mr].getIcon ()==tile_img[1])
{
if(tile[mp].getX ()==tile[mr].getX ())
{
if((tile[mr].getY ()>tile[mp].getY()) && (tile[mp+11].getIcon ()==tile_img[2]) && (tile[mr]==tile[mp+22]) )
{
find=true;
break;
}
if((tile[mr].getY ()
find=true;
break;
}
}
if(tile[mp].getY()==tile[mr].getY ())
{
if((tile[mr].getX ()>tile[mp].getX()) && (tile[mp+1].getIcon ()==tile_img[2])&& (tile[mr]==tile[mp+2]))
{
find=true;
break;
}
if((tile[mr].getX ()
find=true;
break;
}
}
}
}
if(find==false)
{
JOptionPane.showMessageDialog (this,"No Legal Move left\n Game is over\nballs left: "+total_ball,"Game Over",JOptionPane.INFORMATION_MESSAGE);
}
}
public void hint()
{
System.out.println("in hint");
if(mp_pos==tile.length-1)
{
mp_pos=0;
}
for(mp=mp_pos;mp
if(tile[mp].getIcon ()==tile_img[2])
if(tile[mr].getIcon ()==tile_img[1])
{
if(tile[mp].getX ()==tile[mr].getX ())
{
if((tile[mr].getY ()>tile[mp].getY()) && (tile[mp+11].getIcon ()==tile_img[2]) && (tile[mr]==tile[mp+22]) )
{
tile[mp].setBorder (BorderFactory.createLineBorder (Color.red));
tile[mr].setBorder (BorderFactory.createLineBorder (Color.green));
break;
}
if((tile[mr].getY ()
tile[mp].setBorder (BorderFactory.createLineBorder (Color.red));
tile[mr].setBorder (BorderFactory.createLineBorder (Color.green));
break;
}
}
if(tile[mp].getY()==tile[mr].getY ())
{
if((tile[mr].getX ()>tile[mp].getX()) && (tile[mp+1].getIcon ()==tile_img[2])&& (tile[mr]==tile[mp+2]))
{
tile[mp].setBorder (BorderFactory.createLineBorder (Color.red));
tile[mr].setBorder (BorderFactory.createLineBorder (Color.green));
break;
}
if((tile[mr].getX ()
tile[mp].setBorder (BorderFactory.createLineBorder (Color.red));
tile[mr].setBorder (BorderFactory.createLineBorder (Color.green));
break;
}
}
}
}
}
}
//Editor
import javax.swing.*;
import java.util.Date;
import java.io.*;
import java.awt.*;
import java.net.*;
import java.awt.event.*;
public class editor extends JFrame implements MouseListener, ActionListener
{
private JLabel tile[],status_bar;
private ImageIcon tile_img[];
private Container c;
private int max_tile=99;
private JMenuItem new_f,open_f,save_f,exit_f,compile_f;
private String text;
private int w=50,h=55;
private File fs;
private boolean save_status=false;
public editor()
{
c=getContentPane();
text=new String("Beat it Editor");
status_bar=new JLabel();
tile_img=new ImageIcon[3];
tile_img[0]=null;
tile_img[1]=new ImageIcon("tile1.jpg");
tile_img[2]=new ImageIcon("tile&ball1.jpg");
ImageIcon beat_it=new ImageIcon("beat_it.ico");
tile=new JLabel[max_tile];
JPanel panel=new JPanel();
panel.setLayout (null);
for(int i=0;i
tile[i]=new JLabel();
tile[i].addMouseListener (this);
tile[i].setSize (w,h);
}
int count=1,lx=20,ly=5;
for(int i=0;i
tile[i].setLocation (lx,ly);
lx+=w;
if(count%11==0)
{
ly+=h;
lx=20;
}
panel.add (tile[i]);
count++;
}
c.add (panel,BorderLayout.CENTER);
c.add (status_bar,BorderLayout.SOUTH);
JMenu file=new JMenu("File");
new_f= new JMenuItem("New",'n');
open_f=new JMenuItem("Open...",'o');
save_f=new JMenuItem("Save...",'s');
compile_f=new JMenuItem("Compile...",'c');
exit_f=new JMenuItem("Exit",'x');
new_f.addActionListener (this);
open_f.addActionListener (this);
save_f.addActionListener (this);
compile_f.addActionListener (this);
exit_f.addActionListener (this);
file.add (new_f);;
file.add (open_f);
file.add (save_f);
file.add(compile_f);
file.add (exit_f);
JMenuBar bar=new JMenuBar();
bar.add (file);
super.setJMenuBar (bar);
super.setTitle (text+" Untitled");
super.setBounds(25,25,600,650);
super.setResizable (false);
super.setVisible (true);
super.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
for(int i=0;i
System.out.println(i+":\theight:"+tile[i].getHeight ()+"\twidth\t"+
tile[i].getWidth ());
}
}
public void mouseClicked (MouseEvent e)
{}
public void mousePressed (MouseEvent e)
{}
public void mouseReleased (MouseEvent e)
{
JLabel temp=new JLabel();
temp=(JLabel)e.getSource ();
System.out.println("in mouse released");
if((JLabel)e.getSource ()==temp)
{
if(e.getButton ()==e.BUTTON1)
{
System.out.println("button1 released");
if(temp.getIcon ()!=tile_img[1])
temp.setIcon (tile_img[1]);
else
{
temp.setIcon (tile_img[0]);
}
}
if(e.getButton ()==e.BUTTON3)
{
System.out.println("button3 released");
if(temp.getIcon ()!=tile_img[2])
{
temp.setIcon (tile_img[2]);
}
else
{
temp.setIcon (tile_img[0]);
}
}
}
}
public void mouseEntered (MouseEvent e)
{}
public void mouseExited (MouseEvent e)
{}
public void actionPerformed (ActionEvent e)
{
if((JMenuItem)e.getSource ()==new_f)
{
System.out.println("in new_f event");
new_d();
}
if((JMenuItem)e.getSource ()==open_f)
{
System.out.println("in open_f event");
open();
}
if((JMenuItem)e.getSource ()==save_f)
{
System.out.println("in save_f event");
save();
}
if((JMenuItem)e.getSource ()==compile_f)
{
System.out.println("in exit_f event");
compile_save();
}
if((JMenuItem)e.getSource ()==exit_f)
{
System.out.println("in exit_f event");
super.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
super.dispose ();
}
}
public void write_compile(File fi)
{
try
{
//File f=new File("c:/ksm/temp11.game");
File f=new File(fi.getAbsolutePath ());
System.out.println("file selected:\t"+f);
FileOutputStream fos=new FileOutputStream(f);
DataOutputStream dos=new DataOutputStream(fos);
dos.writeInt (30139);
for(int i=0;i
if(tile[i].getIcon ()==tile_img[1])
dos.writeByte(1);
else if(tile[i].getIcon ()==tile_img[2])
dos.writeByte (2);
else if(tile[i].getIcon ()==tile_img[0])
dos.writeByte(0);
}
dos.flush ();
dos.close ();
}
catch(IOException ioe)
{}
}
public void write(File fi)
{
try
{
//File f=new File("c:/ksm/temp11.game");
File f=new File(fi.getAbsolutePath ());
System.out.println("file selected:\t"+f);
FileOutputStream fos=new FileOutputStream(f);
DataOutputStream dos=new DataOutputStream(fos);
int t=0,b=0;
for(int i=0;i
if(tile[i].getIcon ()==tile_img[1])
{
dos.writeInt (1);
t++;
}
else if(tile[i].getIcon ()==tile_img[2])
{
dos.writeInt (2);
b++;
}
else if(tile[i].getIcon ()==tile_img[0])
{
dos.writeInt (0);
}
}
dos.flush ();
dos.close ();
String t1=new String(" empty tile: "+t+" ,tile with ball: "+b);
status_bar.setText(t1);
}
catch(IOException ioe)
{}
}
public void read(File fi)
{
try
{
//File f=new File("c:/ksm/temp11.game");
File f=new File(fi.getAbsolutePath ());
System.out.println("file selected:\t"+f);
FileInputStream fis=new FileInputStream(f);
DataInputStream dis=new DataInputStream(fis);
int status=0,t=0,b=0;
for(int i=0;i
status=dis.readInt ();
tile[i].setIcon (tile_img[status]);
if(tile[i].getIcon ()==tile_img[1])
{
t++;
}
else if(tile[i].getIcon ()==tile_img[2])
{
b++;
}
else if(tile[i].getIcon ()==tile_img[0])
{}
}
dis.close ();
String t1=new String(" empty tile: "+t+" , tile with ball: "+b);
status_bar.setText(t1);
}
catch(IOException ioe)
{}
}
public void new_d()
{
for(int i=0;i
tile[i].setIcon(null);
}
}
public void open()
{
JFileChooser fc=new JFileChooser("C:ksm/beat_it/games");
fc.setFileSelectionMode (JFileChooser.FILES_ONLY);
filter filter=new filter("template");
fc.addChoosableFileFilter (filter);
int result=fc.showOpenDialog (open_f);
if(result==JFileChooser.APPROVE_OPTION)
{
fs=fc.getSelectedFile ();
if(fs.exists ()==true && fs.isFile ()==true)
{
read(fs);
super.setTitle (text+" "+fs.getName ());
save_status=true;
}
else
JOptionPane.showMessageDialog (this,"invalid file selected","Invalid File",
JOptionPane.ERROR_MESSAGE);
}
}
public void save()
{
JFileChooser fc=new JFileChooser("C:ksm/beat_it/games");
fc.setFileSelectionMode (JFileChooser.FILES_ONLY);
filter filter=new filter("template");
fc.addChoosableFileFilter (filter);
int result=fc.showSaveDialog (open_f);
if(result==JFileChooser.APPROVE_OPTION)
{
fs=fc.getSelectedFile ();
String temp=new String(fs.getPath ());
temp+=".template";
File f=new File(temp);
save_status=true;
super.setTitle (text+" "+f.getName ());
write(f);
}
}
public void compile_save()
{
if(save_status==false)
{
JOptionPane.showMessageDialog (this,"Please save it before compile","Save it...",JOptionPane.INFORMATION_MESSAGE);
}
if(save_status==true)
{
String temp=new String(fs.getPath ());
temp+=".game";
File f=new File(temp);
write_compile(f);
}
}
}
//Filter
import javax.swing.filechooser.FileFilter;
import java.io.File;
public class filter extends FileFilter
{
private String ext;
public filter (String e)
{
ext=new String(e);
}
public boolean accept (File f)
{
if(f.getPath ().endsWith ("."+ext))
return true;
return false;
}
public String getDescription ()
{
String temp=new String();
temp=ext+" Files (*."+ext+")";
return temp;
}
}
//mp3
import javax.media.*;
import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
public class mp3 extends JFrame implements ActionListener
{
private Player player;
private JButton play_btn,next_btn,stop_btn;
private File fl[];
private int count=0;
boolean status=false;
private JMenuItem open_f,exit_f;
private Vector list;
public mp3 ()
{
JMenu file=new JMenu("File");
open_f=new JMenuItem("ADD...");
exit_f=new JMenuItem("Exit");
open_f.addActionListener (this);
exit_f.addActionListener (this);
file.add (open_f);
file.add (exit_f);
JMenuBar bar=new JMenuBar();
bar.add (file);
play_btn=new JButton("PLAY");
next_btn=new JButton("NEXT");
stop_btn=new JButton("STOP");
next_btn.setEnabled (false);
stop_btn.setEnabled (false);
JPanel panel=new JPanel(new GridLayout(1,3));
panel.add (play_btn);
panel.add(next_btn);
panel.add(stop_btn);
//File f=new File("c:/ksm/mp3");
list=new Vector(1,1);
play_btn.addActionListener(this);
next_btn.addActionListener(this);
stop_btn.addActionListener(this);
Container c=getContentPane();
c.add(panel,BorderLayout.SOUTH);
super.setJMenuBar (bar);
super.setResizable (false);
super.setBounds (10,10,400,100);
super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
super.setVisible (true);
}
public void actionPerformed (ActionEvent e)
{
if(e.getSource ()==play_btn)
{
play_btn.setEnabled (false);
next_btn.setEnabled (true);
stop_btn.setEnabled (true);
play_mp3(count);
}
if(e.getSource ()==next_btn)
{
if(count==list.size()-1)
{
count=0;
}
else
{
count++;
}
play_mp3(count);
}
if(e.getSource ()==stop_btn)
{
player.stop ();
play_btn.setEnabled (true);
next_btn.setEnabled (false);
stop_btn.setEnabled (false);
}
if(e.getSource ()==open_f)
{
System.out.println("in open_f event");
open();
}
if(e.getSource ()==exit_f)
{
System.out.println("in exit_f event");
super.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
super.dispose();
}
}
public void play_mp3(int v)
{
if(status==true)
{
player.stop();
status=false;
}
if(status==false)
{
try
{
File temp=(File)list.get(v);
player=Manager.createPlayer(temp.toURL ());
super.setTitle("MP3 player "+temp.getName());
player.start();
status=true;
}
catch(Exception murle)
{
System.out.println("in murle");
}
}
}
public void open()
{
JFileChooser fc=new JFileChooser("C:ksm/mp3");
fc.setFileSelectionMode (JFileChooser.FILES_ONLY);
filter filter=new filter("mp3");
fc.addChoosableFileFilter (filter);
int result=fc.showOpenDialog (open_f);
if(result==JFileChooser.APPROVE_OPTION)
{
File f=fc.getSelectedFile ();
if(f.exists ()==true && f.isFile ()==true)
{
list.add (f);
for(int i=0;i
System.out.println(list.get (i));
}
}
else
JOptionPane.showMessageDialog (this,"invalid file selected","Invalid File",
JOptionPane.ERROR_MESSAGE);
}
}
public static void main(String arg[])
{
mp3 obj=new mp3();
obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
No comments:
Post a Comment