Answer to Question #273635 in Java | JSP | JSF for Memo

Question #273635

On the form, create two combo boxes, to allow a user to select between three



different printers and years. When a user has selected a printer and year and clicked



the submit button, display the amount of ink cartridges used for that year. Use the



following table for the printers and yearly cartridges used:



2018 2019 2020



HP Deskjesk 650 10 35 20



Epson K750 15 22 12



Canon Z100 30 31 33



Q.1.2 You are also required to create a menu system which will allow the user to exit the



application under the file menu. Under the tool’s menu, allow the form submission



and an option to display the yearly ink cartridges used for each printer. The layout



of the form is left to your discretion. Marks will be allocated to the presentation and



effectiveness of the layout, but the following layout is displayed for your



convenience.

1
Expert's answer
2021-11-30T18:41:31-0500


package printersyear;
import javax.swing.JOptionPane;  
public class printerYear extends javax.swing.JPanel {


    
    public printerYear() {
        initComponents();
    }


   
                     
    private void initComponents() {


        jPanel1 = new javax.swing.JPanel();
        jComboBox1 = new javax.swing.JComboBox<>();
        jComboBox2 = new javax.swing.JComboBox<>();
        jButton1 = new javax.swing.JButton();


        jComboBox1.setBackground(new java.awt.Color(255, 255, 0));
        jComboBox1.setFont(new java.awt.Font("Times New Roman", 3, 12)); // NOI18N
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "2018", "2019", "2020" }));


        jComboBox2.setFont(new java.awt.Font("Times New Roman", 3, 14)); // NOI18N
        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "HP Deskjesk 650", "Epson K750", "Canon Z100" }));


        jButton1.setFont(new java.awt.Font("Times New Roman", 3, 18)); // NOI18N
        jButton1.setForeground(new java.awt.Color(0, 204, 204));
        jButton1.setText("Submit");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });


        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 81, Short.MAX_VALUE)
                .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(108, 108, 108))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(69, 69, 69)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 76, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(77, 77, 77))
        );


        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
    }                      


    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        int index = jComboBox1.getSelectedIndex();
        Object printer = jComboBox1.getItemAt(index);
        
         int year= jComboBox2.getSelectedIndex();
        Object year_selected = jComboBox2.getItemAt(year);
        if(printer=="HP Deskjesk 650" && year_selected== "2018"){
            JOptionPane.showMessageDialog(null, "The amount of ink cartridges used for "+ year_selected+ " is 10");
        }
        else if(printer=="HP Deskjesk 650" && year_selected== "2019"){
           JOptionPane.showMessageDialog(null, "The amount of ink cartridges used for "+ year_selected+ " is 35");  
        }
        
        else if(printer=="HP Deskjesk 650" && year_selected== "2020"){
           JOptionPane.showMessageDialog(null, "The amount of ink cartridges used for "+ year_selected+ " is 20");  
        }
        
        else if(printer=="Epson K750" && year_selected== "2018"){
           JOptionPane.showMessageDialog(null, "The amount of ink cartridges used for "+ year_selected+ " is 15");  
        }
        
        else if(printer=="Epson K750" && year_selected== "2019"){
           JOptionPane.showMessageDialog(null, "The amount of ink cartridges used for "+ year_selected+ " is 22");  
        }
        
        else if(printer=="Epson K750" && year_selected== "2019"){
           JOptionPane.showMessageDialog(null, "The amount of ink cartridges used for "+ year_selected+ " is 12");  
        }
        
        else if(printer=="Canon Z100" && year_selected== "2018"){
           JOptionPane.showMessageDialog(null, "The amount of ink cartridges used for "+ year_selected+ " is 30");  
        }
        else if(printer=="Canon Z100" && year_selected== "2019"){
            
            
           JOptionPane.showMessageDialog(null, "The amount of ink cartridges used for "+ year_selected+ " is 31");  
        }
        else if(printer=="Canon Z100" && year_selected== "2020"){
           JOptionPane.showMessageDialog(null, "The amount of ink cartridges used for "+ year_selected+ " is 33");  
        }
       
        
       
    }                                        




                        
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox<String> jComboBox1;
    private javax.swing.JComboBox<String> jComboBox2;
    private javax.swing.JPanel jPanel1;
                    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS