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 HP Deskjesk 650 10 35 20
2019 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
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.*;
public class Main extends JFrame implements ActionListener{
JFrame frame;
JComboBox c1;
JComboBox c2;
JButton submit;
Main(){
frame =new JFrame("Printers");
String disp[]={"HP Deskjesk 650","Epson K750","Canon Z100"};
String year[]={"2018", "2019", "2020" };
c2 =new JComboBox(disp);
c2.setBounds(100, 100,100,20);
c1=new JComboBox(year);
c1.setBounds(100, 200,100,20);
frame.add(c2);
frame.add(c1);
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 Main();
}
public void actionPerformed(ActionEvent ae) {
int index = c2.getSelectedIndex();
Object printer = c2.getItemAt(index);
int year_index = c1.getSelectedIndex();
Object year = c1.getItemAt(year_index);
if(printer=="HP Deskjesk 650" && year== "2018"){
JOptionPane.showMessageDialog(null, "Ink cartridges amount for "+ year+ " is 10");
}
else if(printer=="HP Deskjesk 650" && year== "2019"){
JOptionPane.showMessageDialog(null, "Ink cartridges amount for "+ year+ " is 35");
}
else if(printer=="HP Deskjesk 650" && year== "2020"){
JOptionPane.showMessageDialog(null, "Ink cartridges amount for "+ year+ " is 20");
}
else if(printer=="Epson K750" && year== "2018"){
JOptionPane.showMessageDialog(null, "Ink cartridges amount for "+ year+ " is 15");
}
else if(printer=="Epson K750" && year== "2019"){
JOptionPane.showMessageDialog(null, "Ink cartridges amount for "+ year+ " is 22");
}
else if(printer=="Epson K750" && year== "2019"){
JOptionPane.showMessageDialog(null, "Ink cartridges amount for "+ year+ " is 12");
}
else if(printer=="Canon Z100" && year== "2018"){
JOptionPane.showMessageDialog(null, "Ink cartridges amount for "+ year+ " is 30");
}
else if(printer=="Canon Z100" && year== "2019"){
JOptionPane.showMessageDialog(null, "Ink cartridges amount for "+ year+ " is 31");
}
else if(printer=="Canon Z100" && year== "2020"){
JOptionPane.showMessageDialog(null, "Ink cartridges amount for "+ year+ " is 33");
}
}
}
Comments
Leave a comment