Results 1 to 10 of 10
  1. #1
    Chri is offline Member
    Join Date
    Aug 2012
    Location
    Switzerland
    Posts
    49
    Rep Power
    0

    Default JFrame won't open

    Hi everyone
    I'm going insane trying to fix this code, it's a simple JFrame that is supposed to write the text you write in a text field in a specific file, specified by the choose in a combo box

    Java Code:
    import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Formatter;
    
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JTextField;
    
    public class inserisciVoto extends JFrame {
    
    
    	
    	
    	private JComboBox materia;
    	private JTextField tf;
    	private JButton ok;
    	private JLabel lab1;
    	String nomiMaterie[] = {"Matematica", "Fisica", "Chimica", "Biologia", "Greco", "Latino", "Storia dell'arte", "Musica", "Francese", "Italiano", "Storia", "Geografia"};
    	String svoto = tf.getText();
    	private Formatter votiTxtM;
    	private Formatter votiTxtF;
    	private Formatter votiTxtC;
    	private Formatter votiTxtB;
    	private Formatter votiTxtG;
    	private Formatter votiTxtL;
    	private Formatter votiTxtSTAR;
    	private Formatter votiTxtMus;
    	private Formatter votiTxtFra;
    	private Formatter votiTxtI;
    	private Formatter votiTxtS;
    	private Formatter votiTxtGeo;
    	
    	
    	
    	
    	public inserisciVoto(){
    		super("Inserisci un voto");
    		setLayout(new FlowLayout());
    		JComboBox materia = new JComboBox(nomiMaterie);
    		JLabel lab1 = new JLabel ("in quale materia?");
    		JTextField tf = new JTextField("inserisci il voto qui");
    		JButton ok = new JButton("Vai");
    		
    		add(lab1, BorderLayout.NORTH);
    		add(materia, BorderLayout.LINE_START);
    		add(tf, BorderLayout.LINE_END);
    		add(ok, BorderLayout.SOUTH);
    		final int mat = materia.getSelectedIndex();
    		
    		
    		try{
    			votiTxtM = new Formatter("votiM.txt");
    			}
    			catch(Exception e){
    				JOptionPane.showMessageDialog(null, "ERRORE");
    			}
    		try{
    			votiTxtF = new Formatter("votiF.txt");
    			}
    			catch(Exception e){
    				JOptionPane.showMessageDialog(null, "ERRORE");
    			}
    		try{
    			votiTxtC = new Formatter("votiC.txt");
    			}
    			catch(Exception e){
    				JOptionPane.showMessageDialog(null, "ERRORE");
    			}
    		try{
    			votiTxtB = new Formatter("votiB.txt");
    			}
    			catch(Exception e){
    				JOptionPane.showMessageDialog(null, "ERRORE");
    			}
    		try{
    			votiTxtG = new Formatter("votiG.txt");
    			}
    			catch(Exception e){
    				JOptionPane.showMessageDialog(null, "ERRORE");
    			}
    		try{
    			votiTxtL = new Formatter("votiL.txt");
    			}
    			catch(Exception e){
    				JOptionPane.showMessageDialog(null, "ERRORE");
    			}
    		try{
    			votiTxtSTAR = new Formatter("votiSTAR.txt");
    			}
    			catch(Exception e){
    				JOptionPane.showMessageDialog(null, "ERRORE");
    			}
    		try{
    			votiTxtMus = new Formatter("votiMus.txt");
    			}
    			catch(Exception e){
    				JOptionPane.showMessageDialog(null, "ERRORE");
    			}
    		try{
    			votiTxtFra = new Formatter("votiFra.txt");
    			}
    			catch(Exception e){
    				JOptionPane.showMessageDialog(null, "ERRORE");
    			}
    		try{
    			votiTxtI = new Formatter("votiI.txt");
    			}
    			catch(Exception e){
    				JOptionPane.showMessageDialog(null, "ERRORE");
    			}
    		try{
    			votiTxtS = new Formatter("votiS.txt");
    			}
    			catch(Exception e){
    				JOptionPane.showMessageDialog(null, "ERRORE");
    			}
    		try{
    			votiTxtGeo = new Formatter("votiGeo.txt");
    		}
    		catch(Exception e){
    			JOptionPane.showMessageDialog(null, "ERRORE");
    		}
    		
    		
    		ok.addActionListener(
    				new ActionListener(){
    					public void actionPerformed(ActionEvent event){
    						
    						double voto = Double.parseDouble(svoto);
    						
    						if(voto<=6 && voto>=1){
    							
    							if(mat== 0){
    							
    							votiTxtM.format("%s", voto);
    							votiTxtM.close();
    							}
    							
    							else if(mat== 1){
    								
    								votiTxtF.format("%s", voto);
    								votiTxtF.close();
    							}
    							
    							else if(mat== 2){
    								
    								votiTxtC.format("%s", voto);
    								votiTxtC.close();
    							}
    							
    							else if(mat== 3){
    								
    								votiTxtB.format("%s", voto);
    								votiTxtB.close();
    							}
    							
    							else if(mat== 4){
    								
    								votiTxtG.format("%s", voto);
    								votiTxtG.close();
    							}
    							
    							else if(mat== 5){
    								
    								votiTxtL.format("%s", voto);
    								votiTxtL.close();
    							}
    							
    							else if(mat== 6){
    								
    								votiTxtSTAR.format("%s", voto);
    								votiTxtSTAR.close();
    							}
    							else if(mat== 7){
    							
    								votiTxtMus.format("%s", voto);
    								votiTxtMus.close();
    							}
    							else if(mat== 8){
    								
    								votiTxtFra.format("%s", voto);
    								votiTxtFra.close();
    							}
    							else if(mat== 9){
    								
    								votiTxtI.format("%s", voto);
    								votiTxtI.close();
    							}
    							else if(mat== 10){
    							
    								votiTxtS.format("%s", voto);
    								votiTxtS.close();
    							}
    						
    						
    							else if(mat== 11){
    							
    							votiTxtGeo.format("%s", voto);
    							votiTxtGeo.close();
    						}
    						}
    						else {
    							JOptionPane.showMessageDialog(null, "Il voto dev'essere compreso tra 1 e 6!");
    						}
    						
    					}
    				
    	}
    
    				);
    			
    		
    		
    		
    	}
    	
    }

    but the frame won't open, no matter how I call it :(

  2. #2
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default Re: JFrame won't open

    setVisible(true);

  3. #3
    Chri is offline Member
    Join Date
    Aug 2012
    Location
    Switzerland
    Posts
    49
    Rep Power
    0

    Default Re: JFrame won't open

    I obviously did it lol, here's how I call it

    Java Code:
    	inserisciVoto insV = new inserisciVoto();
    		insV.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		insV.setSize(500,200);
    		insV.setVisible(true);

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  5. #5
    Chri is offline Member
    Join Date
    Aug 2012
    Location
    Switzerland
    Posts
    49
    Rep Power
    0

    Default Re: JFrame won't open

    no, i had already put it before posting the code, but it didn't work

  6. #6
    Chri is offline Member
    Join Date
    Aug 2012
    Location
    Switzerland
    Posts
    49
    Rep Power
    0

    Default Re: JFrame won't open

    Quote Originally Posted by Chri View Post
    no, i had already put it before posting the code, but it didn't work
    Up...the problem isn't solved

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default Re: JFrame won't open

    So, since it's not displaying, it might be an idea to show the code that is supposed to show the JFrame.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    Chri is offline Member
    Join Date
    Aug 2012
    Location
    Switzerland
    Posts
    49
    Rep Power
    0

    Default Re: JFrame won't open

    it's above...I'll repost it
    Java Code:
    inserisciVoto insV = new inserisciVoto();
        insV.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        insV.setSize(500,200);
        insV.setVisible(true);
    EDIT:
    I did it...thanks anyway
    Last edited by Chri; 11-05-2012 at 10:48 PM.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default Re: JFrame won't open

    And what was wrong?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    Chri is offline Member
    Join Date
    Aug 2012
    Location
    Switzerland
    Posts
    49
    Rep Power
    0

    Default Re: JFrame won't open

    I moved
    String svoto = tf.getText();

    to the actionPerformed method changing it to final

Similar Threads

  1. Close a JFrame, but keep the original open.
    By nolsen01 in forum AWT / Swing
    Replies: 3
    Last Post: 06-13-2011, 11:28 PM
  2. how to open a new JFrame from a JFrame
    By nashbender in forum AWT / Swing
    Replies: 7
    Last Post: 05-24-2011, 04:57 AM
  3. How to open new JFrame with clicking on button?
    By phearless in forum AWT / Swing
    Replies: 1
    Last Post: 01-14-2011, 10:36 AM
  4. How To Open a JFrame Form from a jButton
    By Lyricid in forum AWT / Swing
    Replies: 12
    Last Post: 03-28-2010, 06:53 AM
  5. Open JFrame
    By AndersBjörnör in forum AWT / Swing
    Replies: 2
    Last Post: 12-01-2009, 09:03 PM

Posting Permissions

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