Results 1 to 3 of 3
  1. #1
    maki is offline Member
    Join Date
    Aug 2013
    Posts
    1
    Rep Power
    0

    Default JTextField problem

    hi to everybody, my first message and is for a problem...
    i've create a main class that i use to call method and generate the view from another class.
    in this second class i construct a JFrame and set all option that i want, as size, color, position etc. i load 10 image on that jframe and set their positions. until here all is going good.
    now i need to put a JTextField in that window (for take a word, and check it as a psw) but if in the second class i create the JTextField it show 2 behaviour (depends in which way i wrote it), in first it cover all window and in second doesn't show at all.

    i wanna ask too if is correct have a main class file, almost empty, and use it only to call method from other class file to construct the program.

    thx for reading

    edit:
    here some code

    this is my main class file
    Java Code:
    package progettoesame;
    
    public class ProgettoEsame {
        
        public static void main(String[] args) {
            Base lancio = new Base();
            lancio.costruzione();
            lancio.immagini();
        }
    }
    and this is my code in a secon class (another file)
    Java Code:
    package progettoesame;
    import java.awt.*;
    import javax.swing.*;
    
    public class Base extends JFrame {
        private ImageIcon capo, cucina, regia, responsabile, sceneggiatore, segretario, stagista, tecnico, designer, jolly;
        private JLabel labelCapo, labelCucina, labelRegia, labelRespo, labelScene, labelSegre, labelStagi, labelTecnico, labelDesig, labelJolly;
        public void costruzione() {
            JFrame vistaIniziale = new JFrame("progetto esame");
            vistaIniziale.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            vistaIniziale.getContentPane().setBackground(Color.black);
            vistaIniziale.setSize(1440, 900);
            vistaIniziale.setLocationRelativeTo(null);
            vistaIniziale.setVisible(true);
        }
        public void immagini() {
                capo = new ImageIcon(getClass().getResource("img_capo.jpg"));
                labelCapo = new JLabel(capo);
                add(labelCapo);
                cucina = new ImageIcon(getClass().getResource("img_cucina.jpg"));
                labelCucina = new JLabel(cucina);
                add(labelCucina);
                regia = new ImageIcon(getClass().getResource("img_regista.jpg"));
                labelRegia = new JLabel(regia);
                add(labelRegia);
                responsabile = new ImageIcon(getClass().getResource("img_responsabile.jpg"));
                labelRespo = new JLabel(responsabile);
                add(labelRespo);
                sceneggiatore = new ImageIcon(getClass().getResource("img_sceneggiatore.jpg"));
                labelScene = new JLabel(sceneggiatore);
                add(labelScene);
                segretario = new ImageIcon(getClass().getResource("img_segretario.jpg"));
                labelSegre = new JLabel(segretario);
                add(labelSegre);
                stagista = new ImageIcon(getClass().getResource("img_stagista.jpg"));
                labelStagi = new JLabel(stagista);
                add(labelStagi);
                tecnico = new ImageIcon(getClass().getResource("img_tecnico.jpg"));
                labelTecnico = new JLabel(tecnico);
                add(labelTecnico);
                designer = new ImageIcon(getClass().getResource("img_designer.jpg"));
                labelDesig = new JLabel(designer);
                add(labelDesig);
                jolly = new ImageIcon(getClass().getResource("img_da_nascondere.jpg"));
                labelJolly = new JLabel(jolly);
                add(labelJolly);
                
                labelCapo.setBounds(200, 140, 191, 200);
                labelCucina.setBounds(480, 140, 196, 200);
                labelRegia.setBounds(750, 145, 162, 200);
                labelRespo.setBounds(1000, 160, 244, 200);
                labelScene.setBounds(50, 440, 281, 200);
                labelSegre.setBounds(350, 430, 255, 200);
                labelStagi.setBounds(650, 440, 328, 200);
                labelTecnico.setBounds(1000, 440, 103, 200);
                labelDesig.setBounds(1140, 440, 227, 200);
                labelJolly.setBounds(1, 1, 4, 4);
        }
    }
    if i launch the program the window is created with the parameters that i setted but the 10 image are not displayed. help

    note that i write the following code in a single file the program display the image without problem, but i don't know why.
    Java Code:
    package ProgettoEsame;
    import java.awt.*;
    import javax.swing.*;
    
    public class verifica extends JFrame {
            private ImageIcon capo, cucina, regia, responsabile, sceneggiatore, segretario, stagista, tecnico, designer, jolly;
            private JLabel labelCapo, labelCucina, labelRegia, labelRespo, labelScene, labelSegre, labelStagi, labelTecnico, labelDesig, labelJolly;
            
            verifica() {
                capo = new ImageIcon(getClass().getResource("img_capo.jpg"));
                labelCapo = new JLabel(capo);
                add(labelCapo);
                cucina = new ImageIcon(getClass().getResource("img_cucina.jpg"));
                labelCucina = new JLabel(cucina);
                add(labelCucina);
                regia = new ImageIcon(getClass().getResource("img_regista.jpg"));
                labelRegia = new JLabel(regia);
                add(labelRegia);
                responsabile = new ImageIcon(getClass().getResource("img_responsabile.jpg"));
                labelRespo = new JLabel(responsabile);
                add(labelRespo);
                sceneggiatore = new ImageIcon(getClass().getResource("img_sceneggiatore.jpg"));
                labelScene = new JLabel(sceneggiatore);
                add(labelScene);
                segretario = new ImageIcon(getClass().getResource("img_segretario.jpg"));
                labelSegre = new JLabel(segretario);
                add(labelSegre);
                stagista = new ImageIcon(getClass().getResource("img_stagista.jpg"));
                labelStagi = new JLabel(stagista);
                add(labelStagi);
                tecnico = new ImageIcon(getClass().getResource("img_tecnico.jpg"));
                labelTecnico = new JLabel(tecnico);
                add(labelTecnico);
                designer = new ImageIcon(getClass().getResource("img_designer.jpg"));
                labelDesig = new JLabel(designer);
                add(labelDesig);
                jolly = new ImageIcon(getClass().getResource("img_da_nascondere.jpg"));
                labelJolly = new JLabel(jolly);
                add(labelJolly);
                
                labelCapo.setBounds(200, 140, 191, 200);
                labelCucina.setBounds(480, 140, 196, 200);
                labelRegia.setBounds(750, 145, 162, 200);
                labelRespo.setBounds(1000, 160, 244, 200);
                labelScene.setBounds(50, 440, 281, 200);
                labelSegre.setBounds(350, 430, 255, 200);
                labelStagi.setBounds(650, 440, 328, 200);
                labelTecnico.setBounds(1000, 440, 103, 200);
                labelDesig.setBounds(1140, 440, 227, 200);
                labelJolly.setBounds(1, 1, 4, 4);
            }
            public static void main(String[] args) {
                verifica vista = new verifica();
                vista.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                vista.setVisible(true);
                
                ImageIcon mondo = new ImageIcon("C:/Users/Dany/Documents/NetBeansProjects/Primo/src/primo/immagini/CPUMonitor.jpg");
                vista.setIconImage(mondo.getImage());
            
                vista.getContentPane().setPreferredSize(new Dimension(1440, 900));
                vista.pack();
                vista.getContentPane().setBackground(Color.black);
            
                vista.setLocationRelativeTo(null);
                vista.setVisible(true);
            }
    }
    Last edited by maki; 09-01-2013 at 12:15 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,302
    Rep Power
    20

    Default Re: JTextField problem

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,302
    Rep Power
    20

    Default Re: JTextField problem

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Problem with JTextField
    By waker3210 in forum AWT / Swing
    Replies: 3
    Last Post: 05-17-2012, 06:42 AM
  2. problem with JTextfield..
    By Shahnawaz in forum New To Java
    Replies: 2
    Last Post: 10-04-2011, 08:16 AM
  3. Replies: 0
    Last Post: 08-30-2011, 09:18 AM
  4. Problem's with JTextField
    By DC% in forum AWT / Swing
    Replies: 4
    Last Post: 03-10-2009, 05:33 PM
  5. Got problem with JtextField
    By hungleon88 in forum AWT / Swing
    Replies: 4
    Last Post: 12-06-2008, 03:01 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
  •