Answer to Question #241450 in Java | JSP | JSF for princesses

Question #241450

Develop a Java GUI application that will display the ink cartridge usage of three different printers with a time span of three years. Q.1.1 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-09-27T06:17:47-0400
package printers;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;


import javax.swing.*;   
public class Printers extends JFrame implements ActionListener{
    JFrame frame;  
    JComboBox second;
    JComboBox first;
    JButton submit;
    Printers(){
         frame =new JFrame("Printers");    
         String print[]={"HP Deskjesk 650","Epson K750","Canon Z100"};  
         String year[]={"2018", "2019", "2020" };        
    first =new JComboBox(print);    
   first.setBounds(100, 100,100,20); 


second=new JComboBox(year);    
   second.setBounds(100, 200,100,20);    
    frame.add(first);  
    frame.add(second); 
    submit = new JButton("Submit");
    submit.setBounds(100, 300, 100,20);
    submit.addActionListener(this);
    frame.add(submit);
   frame.setLayout(null);    
    frame.setSize(400,500);    
   frame.setVisible(true);   
   
    }
    
    public static void main(String[] args) {
       new Printers();
               
    }


    @Override
    public void actionPerformed(ActionEvent ae) {
        int index = first.getSelectedIndex();
        Object printer = first.getItemAt(index);
        
         int year_index = second.getSelectedIndex();
        Object year = second.getItemAt(year_index);
        if(printer=="HP Deskjesk 650" && year== "2018"){
            JOptionPane.showMessageDialog(null, "The amount of ink cartridges used for "+ year+ " is 10");
        }
        else if(printer=="HP Deskjesk 650" && year== "2019"){
           JOptionPane.showMessageDialog(null, "The amount of ink cartridges used for "+ year+ " is 35");  
        }
        
        else if(printer=="HP Deskjesk 650" && year== "2020"){
           JOptionPane.showMessageDialog(null, "The amount of ink cartridges used for "+ year+ " is 20");  
        }
        
        else if(printer=="Epson K750" && year== "2018"){
           JOptionPane.showMessageDialog(null, "The amount of ink cartridges used for "+ year+ " is 15");  
        }
        
        else if(printer=="Epson K750" && year== "2019"){
           JOptionPane.showMessageDialog(null, "The amount of ink cartridges used for "+ year+ " is 22");  
        }
        
        else if(printer=="Epson K750" && year== "2019"){
           JOptionPane.showMessageDialog(null, "The amount of ink cartridges used for "+ year+ " is 12");  
        }
        
        else if(printer=="Canon Z100" && year== "2018"){
           JOptionPane.showMessageDialog(null, "The amount of ink cartridges used for "+ year+ " is 30");  
        }
        else if(printer=="Canon Z100" && year== "2019"){
           JOptionPane.showMessageDialog(null, "The amount of ink cartridges used for "+ year+ " is 31");  
        }
        else if(printer=="Canon Z100" && year== "2020"){
           JOptionPane.showMessageDialog(null, "The amount of ink cartridges used for "+ year+ " is 33");  
        }
       
        
       
    }
    
}

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