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

Thread: help fixing the code of gui

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help fixing the code of gui

    Hello can you help me fixing this code? I want to create an archive of photos and I’ve done this code to arrange photos by seasons but the first part I think it’s ok but second no because in the moment that I press the button put in archive I want to show me a confirmation that my photo was put in archive and to ask me if I want to put other photos I’ve written that but that part doesn’t show …..I also wanted to add a part of code that I add 2 other buttons(I know this part) that in the moment that I press for ex “show” it shows me the information about the photo.’ve been struggling with this and I’ve just learnt GUI and I have to do this


    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    public class photoarchive extends JFrame implements ActionListener{
    static String[] archive1={"december","january","february"};
    static String[] archive2={"photo in june ","july ","august"};
    static String[] archive3={"photo in september ","in october","in november "};
    static String[] archive4={"photo in march","april" ,"may"};
    JLabel nrphoto=new JLabel("NR photo ");
    JTextField inrfoto=new JTextField(7);
    JPanel namePanel=new JPanel();
    JPanel nrfotoPanel=new JPanel();
    JRadioButton archiva1= new JRadioButton("winter archive ");
    JRadioButton archiva2= new JRadioButton("summer archive ");
    JRadioButton archiva3= new JRadioButton("autumn archive");
    JRadioButton archiva4= new JRadioButton("spring archive");
    JButton putinarchive = new JButton("put in archive");
    public photoarchive ()
    {super("photoarchive");
    setSize(500,250);
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel name =new JLabel("name of photo");
    JTextField inname=new JTextField(100);
    ButtonGroup fotoGroup=new ButtonGroup();
    fotoGroup.add(archiva1);
    fotoGroup.add(archiva2);
    fotoGroup.add(archiva3);
    fotoGroup.add(archiva4);
    JPanel fotoPanel=new JPanel();
    fotoPanel.setLayout(new BoxLayout(fotoPanel,BoxLayout.Y_AXIS));
    fotoPanel.add(archiva1);
    fotoPanel.add(archiva2);
    fotoPanel.add(archiva3);
    fotoPanel.add(archiva4);
    Container content=getContentPane();
    FlowLayout lay=new FlowLayout(FlowLayout.LEFT);
    content.setLayout(lay);
    inrfoto.addActionListener(this);
    archiva1.addActionListener(this);
    archiva2.addActionListener(this);
    archiva3.addActionListener(this);
    archiva4.addActionListener(this);
    namePanel.add(name);
    namePanel.add(inname);
    nrfotoPanel.add(nrphoto);
    nrfotoPanel.add(inrfoto);
    content.add(namePanel);
    content.add(nrfotoPanel);
    content.add(putinarchive);
    content.add(fotoPanel);
    Component pergjigje = null;
    content.add(pergjigje);
    setContentPane(content);}

    public void actionPerformed(ActionEvent event)
    {String userln;
    userln=nrphoto.getText();
    JLabel pergjigje = null;
    if(event.getSource()==archiva1)
    {int i=0;
    if(i<archive1.length){
    pergjigje.setText("foto"+archive1[i]+"put on archive ");i++;}
    int answer=JOptionPane.showConfirmDialog(null, "would you like to put another photo?");
    if(answer==JOptionPane.YES_OPTION){actionPerformed (event);}
    else
    if(answer==JOptionPane.NO_OPTION){setDefaultCloseO peration(JFrame.EXIT_ON_CLOSE);}
    }
    else{JOptionPane.showMessageDialog(null,"thank you");}
    if(event.getSource()==archiva2)
    {int i=0;
    if(i<archive2.length)
    {archive2[i]=archive2[i+1];pergjigje.setText("foto"+archive2[i]+"put on archive ");i++;}
    int answer=JOptionPane.showConfirmDialog(null,"would you like to put another photo?");
    if(answer==JOptionPane.YES_OPTION){actionPerformed (event);}
    else
    if(answer==JOptionPane.NO_OPTION){
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}
    }
    else{JOptionPane.showMessageDialog(null,"thank you");}
    if(event.getSource()==archiva3)
    {int i=0;
    if(i<archive3.length)
    {archive3[i]=archive3[i+1];pergjigje.setText("foto"+archive3[i]+"put on archive");i++;}
    int answer=JOptionPane.showConfirmDialog(null,"would you like to put another photo?");
    if(answer==JOptionPane.YES_OPTION){actionPerformed (event);}
    else
    if(answer==JOptionPane.NO_OPTION){setDefaultCloseO peration(JFrame.EXIT_ON_CLOSE);}
    else{JOptionPane.showMessageDialog(null,"thank you");}
    {if(event.getSource()==archiva4)
    {
    if(i<archive4.length)
    {archive4[i]=archive4[i+1];pergjigje.setText("foto"+archive4[i]+"u vendos ne arkiv");i++;}
    int answer1 =JOptionPane.showConfirmDialog(null,"would you like to put another photo?");
    if(answer1==JOptionPane.YES_OPTION){actionPerforme d(event);}
    else
    if(answer1==JOptionPane.NO_OPTION){setDefaultClose Operation(JFrame.EXIT_ON_CLOSE);}
    }
    else{JOptionPane.showMessageDialog(null,"thank you");}
    }}}
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    photoarchive arkivim=new photoarchive();
    }



    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: help fixing the code of gui

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting

    Describe what your problems are. What does the code do or not do? Are there errors?
    Be specific

Similar Threads

  1. Help fixing my first program
    By javadude in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 9th, 2012, 06:52 PM
  2. Fixing the scan input
    By Twoacross in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 14th, 2011, 07:42 AM
  3. I am having a hard time fixing this error
    By KuruptingYou in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 28th, 2011, 10:12 PM
  4. Need help fixing Binary Search Tree code
    By fistpunch in forum What's Wrong With My Code?
    Replies: 6
    Last Post: December 6th, 2010, 11:22 AM
  5. [SOLVED] Error of "cannot find symbol"
    By big_c in forum File I/O & Other I/O Streams
    Replies: 31
    Last Post: April 9th, 2009, 11:20 AM