Foro de elhacker.net

Programación => Java => Mensaje iniciado por: mapers en 27 Mayo 2011, 17:54 pm



Título: jLabel
Publicado por: mapers en 27 Mayo 2011, 17:54 pm
beunas señores desearia colocar un JLabel del tamaño de mi Jframe de tal manera que pueda darle la ruta de una imagen para colocarla de fondo me podrian ayudar con esa parte hay esta mi codigo gracias por su ayuda
Código
  1. public class Formularios_ extends JFrame implements ActionListener {
  2.  
  3.  
  4.    private JMenuBar menuBar;
  5.    private JMenu Mostrar_Cocomo;
  6.    private JMenuItem Cocomo, Primera_Tabla, Segunda_T;
  7.    private JMenu mostrar_tabla;
  8.    private Compiz_ Com = new Compiz_();
  9.    private Primera_Tabla PT = new Primera_Tabla();
  10.  
  11.    public Formularios_() {
  12.  
  13.        super("Modelo de Construccion de Costos");
  14.        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  15.        this.setLayout(null);
  16.        this.setSize(400, 400);
  17.  
  18.        this.setResizable(false);
  19.        this.addComponents();
  20.        this.setVisible(true);
  21.        this.setLocationRelativeTo(null);
  22.    }
  23.  
  24.    public void actionPerformed(ActionEvent e) {
  25.  
  26.        if (e.getSource() == Cocomo) {
  27.  
  28.            Com.setVisible(true);
  29.            Com.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  30.        }
  31.        else if(e.getSource()==Primera_Tabla){
  32.            repaint();
  33.            PT.mostrar_codigo();
  34.            PT.setVisible(true);
  35.  
  36.        }
  37.    }
  38.  
  39.    private void addComponents() {
  40.        menuBar = new JMenuBar();
  41.        this.setJMenuBar(menuBar);
  42.        Mostrar_Cocomo = new JMenu("Calculos");
  43.        menuBar.add(Mostrar_Cocomo);
  44.        Cocomo = new JMenuItem("Puntos de Funcion_");
  45.        Segunda_T = new JMenuItem("COCOMO");
  46.  
  47.        Mostrar_Cocomo.add(Cocomo);
  48.        Mostrar_Cocomo.add(Segunda_T);
  49.  
  50.        this.setJMenuBar(menuBar);
  51.        mostrar_tabla = new JMenu("Codigos de entrada ");
  52.        menuBar.add(mostrar_tabla);
  53.        Primera_Tabla = new JMenuItem("Mostrar Codigos Guardados ");
  54.        mostrar_tabla.add(Primera_Tabla);
  55.  
  56.        Primera_Tabla .addActionListener(this);
  57.        Cocomo.addActionListener(this);
  58.    }
  59. }
  60.  
  61.  

gracias por su tiempo en ayudar a gente como yo :D


Título: Re: jLabel
Publicado por: 1mpuls0 en 28 Mayo 2011, 04:04 am
TEMA REPETIDO.
http://foro.elhacker.net/java/poner_una_imagen_en_un_jlabel-t328430.0.html


Esto debe de funcionarte.

Código
  1. import javax.swing.JFrame;
  2. import java.awt.event.ActionListener;
  3. import java.awt.event.ActionEvent;
  4. import javax.swing.JLabel;
  5. import java.awt.FlowLayout;
  6. import java.awt.Dimension;
  7. import javax.swing.ImageIcon;
  8. import javax.swing.JPanel;
  9.  
  10. public class Formularios extends JFrame implements ActionListener {
  11.  
  12. public static void main(String args[]) {
  13. new Formularios();
  14. }
  15.  
  16.  
  17.    /*private JMenuBar menuBar;
  18.     private JMenu Mostrar_Cocomo;
  19.     private JMenuItem Cocomo, Primera_Tabla, Segunda_T;
  20.     private JMenu mostrar_tabla;
  21.     private Compiz_ Com = new Compiz_();
  22.     private Primera_Tabla PT = new Primera_Tabla();*/
  23.  
  24.    public Formularios() {
  25.  
  26.        super("Modelo de Construccion de Costos");
  27.        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  28.        this.setLayout(null);
  29.        this.setSize(400, 400);
  30.  
  31.        this.setResizable(false);
  32.        this.addComponents();
  33.        this.setVisible(true);
  34.        this.setLocationRelativeTo(null);
  35.    }
  36.  
  37.    public void actionPerformed(ActionEvent e) {
  38.  
  39.        /*if (e.getSource() == Cocomo) {
  40.  
  41.             Com.setVisible(true);
  42.             Com.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  43.         }
  44.         else if(e.getSource()==Primera_Tabla){
  45.             repaint();
  46.             PT.mostrar_codigo();
  47.             PT.setVisible(true);
  48.  
  49.         }*/
  50.    }
  51.  
  52.    private void addComponents() {
  53.     JLabel etiquetaIcono;
  54.     JPanel panel;
  55.     etiquetaIcono = new JLabel();
  56.     panel = new JPanel();
  57.  
  58.     getContentPane().setLayout(new FlowLayout());
  59.     panel.setPreferredSize(new Dimension(400, 400));
  60.        panel.setLayout(null);
  61.        /*menuBar = new JMenuBar();
  62.         this.setJMenuBar(menuBar);
  63.         Mostrar_Cocomo = new JMenu("Calculos");
  64.         menuBar.add(Mostrar_Cocomo);
  65.         Cocomo = new JMenuItem("Puntos de Funcion_");
  66.         Segunda_T = new JMenuItem("COCOMO");
  67.  
  68.         Mostrar_Cocomo.add(Cocomo);
  69.         Mostrar_Cocomo.add(Segunda_T);
  70.  
  71.         this.setJMenuBar(menuBar);
  72.         mostrar_tabla = new JMenu("Codigos de entrada ");
  73.         menuBar.add(mostrar_tabla);
  74.         Primera_Tabla = new JMenuItem("Mostrar Codigos Guardados ");
  75.         mostrar_tabla.add(Primera_Tabla);
  76.  
  77.         Primera_Tabla .addActionListener(this);
  78.         Cocomo.addActionListener(this);*/
  79.        etiquetaIcono.setIcon(new ImageIcon(getClass().getResource("fondo.jpg")));
  80.        panel.add(etiquetaIcono);
  81.        etiquetaIcono.setBounds(0, 0, 400, 400);
  82.  
  83.        getContentPane().add(panel);
  84.  
  85.        pack();
  86.    }
  87. }
  88.  

No es la mejor opción pero tampoco es mala.

http://foro.elhacker.net/java/fondo_para_un_jframe_consulta-t321305.0.html
http://foro.elhacker.net/java/poner_una_imagen_en_un_jlabel-t328430.0.html
http://foro.elhacker.net/empty-t296193.0.html

http://cafelojano.wordpress.com/2007/07/20/jframe-con-imagen-de-fondo/



Título: Re: jLabel
Publicado por: mapers en 29 Mayo 2011, 22:36 pm
Oks men muchas gracias me sirvio _:D