Question
For Java, can someone help me understand what the questions were asking for?
Consider the following Java declarations: JComboBox cb = new JComboBox(); JButton b = new JButton (Press); JCheckBox cb = n
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Java Swing is a platform independent Graphical User Interface (GUI) toolkit.

Note:

  • All components in swing are JComponent that must be added to container classes.
  • Mainly 3 types of containers are there. That is, Panel, Frame and Dialogue.
  • We must add all of the swing components to any of the container object.

Working with swing, we should add the below statement.

import javax.swing.*;

The javax.swing package contains classes for java swing API such as JTextField, JButton, JTextArea, JRadioButton, JCheckbox, etc.

  • In the above question,we can see that there are five classes are defined with their objects  jcombobox, JButton, JCheckBox, JTextField and Font.
  • So we dont want to define or creating the object of these classes again. Just make changes of the created classes. When we define a statement with new keyword, we are recreating the object of the class.
  • There are so many methods are available in swing.
  • Some of them are given below.

1) b.setLabel("Submit");

We are already created a jbutton with b as object having a label "Press", To change this label use setLabel() method.

button_object.setLabel(newlabel) is the syntax

2) cb.addItem("Football");

We are created a combobox with object cb. We have to add an item to the end of the list. So, we can use a method addItem() to add item to the combo.

syntax is, object_name.addItem(value);

object_name is the name of the component object. Here cb is the object.

3) rb.setSelected(true);

To set the checkbox to be checked by default, we have set the setSelected to true.The method setSelected() is used to check or uncheck the component. When the value is true, it become checked otherwise unchecked.

4)

//import java.awt.Color;

tf.setForeground(Color.RED);

We should import the Color class. To set the text colour ina textfield, we have to use a method called setForground() method. In the bracket, use Color.color_name. Color_name may be RED, GREEN,BLUE etc. object_name is the textbox's object name.

5) tf.setText("");

To clear the textfield use SetText() method with parametee as two double quotes. If want to set hai as text, type "hai" within the textbox. Like that, empty setText means clear the textfield content. It is also use with textfield object tf.

6)b.setFont(f1);

Here we can see that, the Font class is created with an object f1, which defines Serif as font, BOLD as text style and font size is 12. So font object f1 has all these property. Use setFont() method to change the font in the component.  

Add a comment
Know the answer?
Add Answer to:
For Java, can someone help me understand what the questions were asking for? Consider the following...
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
  • Simple java questions Q2.java: import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Q2 extends JFrame { public static void createAndShowGUI() { JFrame frame = new JFrame(&#3...

    Simple java questions Q2.java: import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Q2 extends JFrame { public static void createAndShowGUI() { JFrame frame = new JFrame("Lab"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = new Font("Sans-serif", Font.BOLD, 20); JLabel label = new JLabel("Enter a word"); label.setFont(font); JTextField textField = new JTextField(10); textField.setFont(font); JButton button = new JButton("Enter"); button.setFont(font); Font font1 = new Font("Sans-serif", Font.BOLD, 30); JCheckBox sansSerif = new JCheckBox("Sans-serif"); sansSerif.setFont(font1); JCheckBox serif= new JCheckBox("Serif"); serif.setFont(font1); Font font2 = new Font("Sans-serif", Font.ITALIC, 15); JRadioButton...

  • JAVA Hello I am trying to add a menu to my Java code if someone can...

    JAVA Hello I am trying to add a menu to my Java code if someone can help me I would really appreacite it thank you. I found a java menu code but I dont know how to incorporate it to my code this is the java menu code that i found. import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem; public class MenuExp extends JFrame { public MenuExp() { setTitle("Menu Example");...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

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