Question

Need help with question 25 program from 9.1 basic programming content. 25.) Write a program to...

Need help with question 25 program from 9.1 basic programming content.

25.) Write a program to question a person about his or her computer and then display a descriptive sentence in a text box. The form should contain combo boxes, for brand, amount of memory, and screen size. The lists should contain the most common responses for each category. Some common computers are Compaq, Dell, Hewlett-Packard, Lenovo, and Apple. The most common amounts of memory are 4GB, 8GB, and 32 GB. The most common screen sizes are 17,19,21,24 and 27 inches.

Thank you and please be descriptive and efficient as possible.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/**
* The java program Configuration that allows programmer
* to select brand , memory size and screen size .
* Then display the selected items from combo box
* in a text field.
* */
//Configuration.java
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class Configuration extends JFrame{
  
   //Set application width, height
   private int APPLICATION_WIDTH=300;
   private int APPLICATION_HEIGHT=350;
   private JTextField txtfield=new JTextField(20);
  
   private JComboBox<String> brandComboBox=null;
   private JComboBox<String> memoryComboBox=null;
   private JComboBox<String> screenComboBox=null;
   private String strdesc="";
  
   public static void main(String[] args) {      
       new Configuration();      
   }
  
  
   //Constructor of class Configuration
   public Configuration() {
       //set size
       setSize(APPLICATION_WIDTH, APPLICATION_HEIGHT);
       //set title
       setTitle("Computer Configuration");      
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       //set layout
       setLayout(new FlowLayout());
       //an array of brands
       String brands[]={"Compaq",
                       "Dell",
                       "Hewlett-Packard",
                       "Lenovo","Apple"};
       //an array of memory
       String memory[]=
               {
               "4",
               "8",
               "32"};
       //an array of sizes
       String sizes[]=
               {
               "17",
               "19",
               "21",
               "24",
               "27"};
       int pos=-1;
      
       brandComboBox=new JComboBox<String>(brands);
       //add action listener for brandComboxBox
       brandComboBox.addActionListener(new ActionListener() {          
           public void actionPerformed(ActionEvent e) {
               int pos=brandComboBox.getSelectedIndex();
               strdesc+="Brand: "+brands[pos];
               txtfield.setText(strdesc);
           }
       });
       memoryComboBox=new JComboBox<String>(memory);
       //add action listener for memoryComboBox
       memoryComboBox.addActionListener(new ActionListener() {          
           public void actionPerformed(ActionEvent e) {
               int pos=memoryComboBox.getSelectedIndex();
               strdesc+=" RAM: "+memory[pos];
               txtfield.setText(strdesc);
           }
       });
       screenComboBox=new JComboBox<String>(sizes);
       //add action listener for screenComboBox
       screenComboBox.addActionListener(new ActionListener() {          
           public void actionPerformed(ActionEvent e) {
               int pos=screenComboBox.getSelectedIndex();
               strdesc+=" Screen Size : "+sizes[pos]+"\"";
               txtfield.setText(strdesc);
           }
       });
      
       //add brandComboBox to frame
       add(brandComboBox);
       //add memoryComboBox to frame
       add(memoryComboBox);
       //add screenComboBox to frame
       add(screenComboBox);      
       //Set a label text and add to frame
       add(new JLabel("You selected :"));  
       //add text field
       add(txtfield);
       //set visibility true
       setVisible(true);  
   }
}

----------------------------------------------------------------------------

Sample Output:

Computer Configuration Compaq ELE 21回 You selected: rand: Compaq RAM: 4 Screen Size 21

Add a comment
Know the answer?
Add Answer to:
Need help with question 25 program from 9.1 basic programming content. 25.) Write a program to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Read about Cokes strategy in Africa in the article below and discuss the ethics of selling...

    Read about Cokes strategy in Africa in the article below and discuss the ethics of selling soft drinks to very poor people. Is this an issue that a company like Coke should consider? Africa: Coke's Last Frontier Sales are flat in developed countries. For Coke to keep growing, Africa is it By Duane Stanford Piles of trash are burning outside the Mamakamau Shop in Uthiru, a suburb of Nairobi, Kenya. Sewage trickles by in an open trench. Across the street,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT