Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package kkkkkkkkk;
- import java.awt.Color;
- /**
- *
- * @author Jeh s2 Roh
- */
- public class NewJFrame extends javax.swing.JFrame {
- /**
- * Creates new form NewJFrame
- */
- public NewJFrame() {
- initComponents();
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jPanel1 = new javax.swing.JPanel();
- jPanel2 = new javax.swing.JPanel();
- Lista = new javax.swing.JComboBox<>();
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 100, Short.MAX_VALUE)
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 100, Short.MAX_VALUE)
- );
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- Lista.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Amarelo", "Azul", "Vermelho", "Rosa" }));
- Lista.setToolTipText("");
- Lista.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
- public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
- }
- public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
- ListaPopupMenuWillBecomeInvisible(evt);
- }
- public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
- }
- });
- Lista.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- ListaActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
- jPanel2.setLayout(jPanel2Layout);
- jPanel2Layout.setHorizontalGroup(
- jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addGap(78, 78, 78)
- .addComponent(Lista, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(88, Short.MAX_VALUE))
- );
- jPanel2Layout.setVerticalGroup(
- jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addGap(74, 74, 74)
- .addComponent(Lista, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(85, Short.MAX_VALUE))
- );
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- );
- pack();
- }// </editor-fold>
- private void ListaActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void ListaPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
- if(Lista.getSelectedItem() == Lista.getItemAt(0)){
- jPanel2.setBackground(Color.yellow);
- }
- if(Lista.getSelectedItem() == Lista.getItemAt(1)){
- jPanel2.setBackground(Color.blue);
- }
- if(Lista.getSelectedItem() == Lista.getItemAt(2)){
- jPanel2.setBackground(Color.red);
- }
- if(Lista.getSelectedItem() == Lista.getItemAt(3)){
- jPanel2.setBackground(Color.pink);
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new NewJFrame().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JComboBox<String> Lista;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JPanel jPanel2;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement