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 3 of 3

Thread: need help on jframe buttonclicked event

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy need help on jframe buttonclicked event

    import java.io.*;
    import java.util.*;


    class musicdata
    {
    String singername;
    String albumname;
    String genre;
    String price;


    public musicdata(String singername,String albumname,String genre, String price)
    {

    this.singername=singername;
    this.albumname=albumname;
    this.genre=genre;
    this.price=price;
    }

    }
    public class NewClass {

    public static void main(String[] args)
    {
    //reading from a file and populating linked list
    File f=new File("d:\\MusicFile.txt");
    int counter=0;
    LinkedList<musicdata> list=new LinkedList<musicdata>();
    try
    {
    BufferedReader br=new BufferedReader(new FileReader(f));
    String str=br.readLine();
    while(str!=null)
    {
    String[] arr=str.split(",");

    list.add(new musicdata(arr[0], arr[1], arr[2], arr[3]));
    str=br.readLine();
    }


    Iterator<musicdata> itr=list.iterator();
    while(itr.hasNext())
    {
    musicdata md=itr.next();
    if(md.genre.equals("Pop"))
    {
    System.out.println(md.singername+" "+md.albumname+" "+md.genre+" "+md.price);
    }
    }

    }catch(IOException ioe)
    {

    }

    }

    }

    i gotta use this programme as inner class to my

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
    }

    i have very less idea about swing inner classes. so please help


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,441
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 544 Posts

    Default Re: need help on jframe buttonclicked event

    When posting code, please use the highlight tags to preserve formatting. I also recommend following naming conventions (classes start with a capital letter) and best practices (empty catch blocks are bad).

    Where exactly are you stuck with this? What have you tried? What are you confused about?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

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

    Default Re: need help on jframe buttonclicked event

    public void run() {
    {
    File f=new File("d:\\MusicFile.txt");
    int counter=0;
    LinkedList<musicdata> list=new LinkedList<musicdata>();
    try
    {
    BufferedReader br=new BufferedReader(new FileReader(f));
    String str=br.readLine();
    while(str!=null)
    {
    String[] arr=str.split(",");

    list.add(new musicdata(arr[0], arr[1], arr[2], arr[3]));
    str=br.readLine();
    }


    Iterator<musicdata> itr=list.iterator();
    while(itr.hasNext())
    {
    musicdata md=itr.next();
    if(md.genre.equals("Pop"))
    {
    JFrame f1=new JFrame("My Frame");
    JPanel frame=new JPanel();
    f1.setVisible(false);
    f1.add(frame);
    JCheckBox chk=new JCheckBox(md.singername+" "+md.albumname+" "+md.genre+" "+md.price);
    f1.setLayout(new FlowLayout());
    f1.add(chk);


    f1.setBounds(100,100,200,200);
    f1.setVisible(true);
    }
    }

    }catch(IOException ioe)
    {
    System.out.println("File Not Foound");
    }

    }
    new HomeForm().setVisible(true);
    }


    ajdh,gadga,Pop,240
    asdfj,gjhjh,Pop,320
    vysy,ahn,Pop,410


    this is the text file context i am reading. i need to create the check boxes for each of three items in panel "JPanel5" in my main jframe form. but as u can see it is opening 3 different frame containing 1 list item in each of it. i need all 3 list item as check boxes in my main form's JPanel5 panel box.

Similar Threads

  1. problem with my JFrame; JFrame not closing and stay in background
    By golominator in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 6th, 2012, 07:20 AM
  2. JFrame in event despatch thread
    By DanielJamesCollier in forum Java Theory & Questions
    Replies: 1
    Last Post: April 25th, 2012, 11:56 AM
  3. using objects from one jFrame on a different jFrame
    By Taskeen in forum AWT / Java Swing
    Replies: 3
    Last Post: September 14th, 2011, 08:51 AM
  4. [SOLVED] jTable event help
    By banny7 in forum AWT / Java Swing
    Replies: 12
    Last Post: August 1st, 2011, 07:42 AM
  5. connecting jframe to another jframe
    By ajtambalo in forum Member Introductions
    Replies: 2
    Last Post: May 11th, 2011, 11:24 AM