jpanel中的java菜单

x6yk4ghg  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(156)

你好,我正在尝试实现一个类似收银员的应用程序,但是我遇到了一个困难,当实现jpanels时,在这种情况下,将我的框架转换为具有不同图像的面板的最佳方法是什么?我试着把我的主屏幕转换成两个面板,一个是菜单,另一个是幻灯片或一组图像

import javax.swing.*;
import javax.swing.JDialog;
import javax.swing.JFrame;
import java.awt.*;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

class PRINCIPAL extends JFrame {

    public PRINCIPAL(){
        setResizable(false);                    //Hace que la ventana sea no modificable
        setTitle("Projecto de Cajero UTC");     //Titulo para la parte de arriba
        setSize(957,760);                       //Tamaño de la app
        JLabel fondo;                           //Declaramos un label para el fondo
        ImageIcon inicio = new ImageIcon("src/main/java/Imagenes/INICIO.png");//Añadimos un icono parra el fondo
        fondo= new JLabel("",inicio,JLabel.LEFT);//Se añade el Fondo al centro en el centro
        fondo.setBounds(50,0,550,0);          //Pixeles calculados para la posicion del fondo respecto al frame
        add(fondo);                             //Añadir
        setLocationRelativeTo(null);            //Ventana al centro

        JButton clickINICIO=new JButton("INICIO"); //Declaramos el boton
        clickINICIO.setFont(new Font("Work Sans", Font.BOLD,20));//Letras
        clickINICIO.setBounds(30,141,192,36);    //Tamaño del boton
        fondo.add(clickINICIO);                  //añadir
        //clickINICIO.setContentAreaFilled(false);//
        //clickINICIO.setBorderPainted(false);// TRANSPARENTE
        //clickINICIO.setOpaque(false);            ////
        //clickINICIO.setFocusable(false);////
        //clickINICIO.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));//Cambiar mouse al pasar el boton

        clickINICIO.addActionListener(new ActionListener()
{
  public void actionPerformed(ActionEvent e)
  {
        JLabel fondo;                           //Declaramos un label para el fondo
        ImageIcon inicio = new ImageIcon("src/main/java/Imagenes/DEPOSITO.png");//Añadimos un icono parra el fondo
        fondo= new JLabel("",inicio,JLabel.LEFT);//Se añade el Fondo al centro en el centro
        fondo.setBounds(50,0,550,0);          //Pixeles calculados para la posicion del fondo respecto al frame
        add(fondo);                             //Añadir
        setLocationRelativeTo(null);            //Ventana al centro

  }
});

        JButton clickSALDO=new JButton("SALDO"); //Declaramos el boton
        clickSALDO.setFont(new Font("Work Sans", Font.BOLD,20));//Letras
        clickSALDO.setBounds(30,199,191,37);    //Tamaño del boton
        fondo.add(clickSALDO);                  //añadir
        //clickSALDO.setContentAreaFilled(false);//
        //clickSALDO.setBorderPainted(false);// TRANSPARENTE
        //clickSALDO.setOpaque(false);            ////
        clickSALDO.setFocusable(false);////
        clickSALDO.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));//Cambiar mouse al pasar el boton

        JButton clickDEPOSITOS=new JButton("DEPOSITOS"); //Declaramos el boton
        clickDEPOSITOS.setFont(new Font("Work Sans", Font.BOLD,20));//Letras
        clickDEPOSITOS.setBounds(30,258,191,37);    //Tamaño del boton
        fondo.add(clickDEPOSITOS);                  //añadir
        //clickDEPOSITOS.setContentAreaFilled(false);//
        //clickDEPOSITOS.setBorderPainted(false);// TRANSPARENTE
        //clickDEPOSITOS.setOpaque(false);            ////
        clickDEPOSITOS.setFocusable(false);////
        clickDEPOSITOS.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));//Cambiar mouse al pasar el boton

        JButton clickRETIROS=new JButton("RETIROS"); //Declaramos el boton
        clickRETIROS.setFont(new Font("Work Sans", Font.BOLD,20));//Letras
        clickRETIROS.setBounds(30,316,191,37);    //Tamaño del boton
        fondo.add(clickRETIROS);                  //añadir
        //clickRETIROS.setContentAreaFilled(false);//
        //clickRETIROS.setBorderPainted(false);// TRANSPARENTE
        //clickRETIROS.setOpaque(false);            ////
        clickRETIROS.setFocusable(false);////
        clickRETIROS.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));//Cambiar mouse al pasar el boton

        JButton clickMOVIMIENTOS=new JButton("MOVIMIENTOS"); //Declaramos el boton
        clickMOVIMIENTOS.setFont(new Font("Work Sans", Font.BOLD,20));//Letras
        clickMOVIMIENTOS.setBounds(30,374,191,39);    //Tamaño del boton
        fondo.add(clickMOVIMIENTOS);                  //añadir
        //clickMOVIMIENTOS.setContentAreaFilled(false);//
        //clickMOVIMIENTOS.setBorderPainted(false);// TRANSPARENTE
        //clickMOVIMIENTOS.setOpaque(false);            ////
        clickMOVIMIENTOS.setFocusable(false);////
        clickMOVIMIENTOS.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));//Cambiar mouse al pasar el boton

        JButton clickSERVICIOS=new JButton("SERVICIOS"); //Declaramos el boton
        clickSERVICIOS.setFont(new Font("Work Sans", Font.BOLD,20));//Letras
        clickSERVICIOS.setBounds(30,432,191,77);//Tamaño del boton
        fondo.add(clickSERVICIOS);                  //añadir
        //clickSERVICIOS.setContentAreaFilled(false);//
        //clickSERVICIOS.setBorderPainted(false);// TRANSPARENTE
        //clickSERVICIOS.setOpaque(false);            ////
        clickSERVICIOS.setFocusable(false);////
        clickSERVICIOS.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));//Cambiar mouse al pasar el boton

        JButton clickAJUSTES=new JButton("AJUSTES"); //Declaramos el boton
        clickAJUSTES.setFont(new Font("Work Sans", Font.BOLD,20));//Letras
        clickAJUSTES.setBounds(30,528,191,39);//Tamaño del boton
        fondo.add(clickAJUSTES);                  //añadir
        //clickAJUSTES.setContentAreaFilled(false);//
        //clickAJUSTES.setBorderPainted(false);// TRANSPARENTE
        //clickAJUSTES.setOpaque(false);            ////
        clickAJUSTES.setFocusable(false);////
        clickAJUSTES.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));//Cambiar mouse al pasar el boton

        JButton clickSALIR=new JButton("SALIR"); //Declaramos el boton
        clickSALIR.setFont(new Font("Work Sans", Font.BOLD,20));//Letras
        clickSALIR.setBounds(30,586,191,39);//Tamaño del boton.
        fondo.add(clickSALIR);                  //añadir
        //clickSALIR.setContentAreaFilled(false);//
        //clickSALIR.setBorderPainted(false);// TRANSPARENTE
        //clickSALIR.setOpaque(false);            ////
        clickSALIR.setFocusable(false);////
        clickSALIR.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));//Cambiar mouse al pasar el boton

    }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题