Java Swing is a platform independent Graphical User Interface (GUI) toolkit.
Note:
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.
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.
For Java, can someone help me understand what the questions were asking for? Consider the following...
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 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 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...