Question stringlengths 1 113 | Answer stringlengths 22 6.98k |
|---|---|
What are the Method Inherited by Canvas Class? | The Canvas has inherited above methods from the following classes:
lang.Component
lang.Object
|
Can you provide the Java AWT Canvas Example? | In the following example, we are creating a Canvas in the Frame and painting a red colored oval inside it.
CanvasExample.java
// importing awt class
import java.awt.*;
// class to construct a frame and containing main method
public class CanvasExample
{
// class constructor
publ... |
What is Java AWT Scrollbar? | The object of Scrollbar class is used to add horizontal and vertical scrollbar. Scrollbar is a GUI component allows us to see invisible number of rows and columns.
It can be added to top-level container like Frame or a component like Panel. The Scrollbar class extends the Component class. |
What is AWT Scrollbar Class Declaration? | public class Scrollbar extends Component implements Adjustable, Accessible |
What are the Scrollbar Class Fields? | static int HORIZONTAL - It is a constant to indicate a horizontal scroll bar.
static int VERTICAL - It is a constant to indicate a vertical scroll bar. |
What are the Constructors of the Scrollbar Class? | Sr. no.1
Constructor: Scrollbar()
Description: Constructs a new vertical scroll bar.
Sr. no.2
Constructor: Scrollbar(int orientation)
Description: Constructs a new scroll bar with the specified orientation.
Sr. no.3
Constructor: Scrollbar(int orientation, int value, int visible, int minimum, int maximum)
Desc... |
What are the Method Inherited by Scrollbar? | The methods of Scrollbar class are inherited from the following classes:
java.awt.Component
java.lang.Object |
What are the Methods of the Scrollbar Class? | Sr. no. 1 Method name: void addAdjustmentListener (AdjustmentListener l)
Description: It adds the given adjustment listener to receive instances of AdjustmentEvent from the scroll bar.
Sr. no. 2 Method name: void addNotify()
Description: It creates the peer of scroll bar.
Sr. no. 3 Method name: int getBlockIncrement(... |
Can you provide a Java AWT Scrollbar Example? | The object of Scrollbar class is used to add horizontal and vertical scrollbar. Scrollbar is a GUI component allows us to see invisible number of rows and columns.
It can be added to top-level container like Frame or a component like Panel. The Scrollbar class extends the Component class. |
Can you provide a Java AWT Scrollbar Example with AdjustmentListener? | In the following example, we are creating a Scrollbar and adding it into the Frame. Here, we are using addAdjustmentListener() method of Scrollbar class which receives the instances of AdjustmentEvent and eventually we display it in the form of Label.
ScrollbarExample2.java
// importing necessary packages
impo... |
What is Java AWT MenuItem and Menu? | The object of MenuItem class adds a simple labeled menu item on menu. The items used in a menu must belong to the MenuItem or any of its subclass.
The object of Menu class is a pull down menu component which is displayed on the menu bar. It inherits the MenuItem class. |
What is AWT MenuItem class declaration? | public class MenuItem extends MenuComponent implements Accessible |
What is AWT Menu class declaration? | public class Menu extends MenuItem implements MenuContainer, Accessible |
Can you provide a Java AWT MenuItem and Menu Example? | import java.awt.*;
class MenuExample
{
MenuExample(){
Frame f= new Frame("Menu and MenuItem Example");
MenuBar mb=new MenuBar();
Menu menu=new Menu("Menu");
Menu submenu=new Menu("Sub Menu");
MenuItem i1=new MenuItem("Item 1");
MenuIt... |
What is Java AWT PopupMenu? | PopupMenu can be dynamically popped up at specific position within a component. It inherits the Menu class. |
What is AWT PopupMenu class declaration? | public class PopupMenu extends Menu implements MenuContainer, Accessible |
Can you provide a Java AWT PopupMenu Example? | import java.awt.*;
import java.awt.event.*;
class PopupMenuExample
{
PopupMenuExample(){
final Frame f= new Frame("PopupMenu Example");
final PopupMenu popupmenu = new PopupMenu("Edit");
MenuItem cut = new MenuItem("Cut");
cut.setActionCommand("Cut");
... |
What is Java AWT Panel?
| The Panel is a simplest container class. It provides space in which an application can attach any other component. It inherits the Container class. |
What is AWT Panel class declaration? | public class Panel extends Container implements Accessible |
Can you provide a Java AWT Panel Example? | import java.awt.*;
public class PanelExample {
PanelExample()
{
Frame f= new Frame("Panel Example");
Panel panel=new Panel();
panel.setBounds(40,80,200,200);
panel.setBackground(Color.gray);
Button b1=new Button("Button 1");
... |
What is Java AWT Dialog? | The Dialog control represents a top level window with a border and a title used to take some form of input from the user. It inherits the Window class.
Unlike Frame, it doesn't have maximize and minimize buttons. |
Frame vs Dialog | Frame and Dialog both inherits Window class. Frame has maximize and minimize buttons but Dialog doesn't have. |
What is AWT Dialog class declaration? | public class Dialog extends Window |
Can you provide a Java AWT Dialog Example? | import java.awt.*;
import java.awt.event.*;
public class DialogExample {
private static Dialog d;
DialogExample() {
Frame f= new Frame();
d = new Dialog(f , "Dialog Example", true);
d.setLayout( new FlowLayout() );
Button b = new Button ("OK");
... |
What is Java AWT Toolkit? | Toolkit class is the abstract superclass of every implementation in the Abstract Window Toolkit. Subclasses of Toolkit are used to bind various components. It inherits Object class. |
What is AWT Toolkit class declaration? | public abstract class Toolkit extends Object |
Can you provide a Java AWT Toolkit Example? | import java.awt.*;
public class ToolkitExample {
public static void main(String[] args) {
Toolkit t = Toolkit.getDefaultToolkit();
System.out.println("Screen resolution = " + t.getScreenResolution());
Dimension d = t.getScreenSize();
System.out.println("Screen width = " + d.w... |
Can you provide a Java AWT Toolkit Example: Change TitleBar Icon? | import java.awt.*;
class ToolkitExample {
ToolkitExample(){
Frame f=new Frame();
Image icon = Toolkit.getDefaultToolkit().getImage("D:\\icon.png");
f.setIconImage(icon);
f.setLayout(null);
f.setSize(400,400);
f.setVisible(true);
}
public static void main(String args[]){
new Too... |
Can you provide a Java ActionListener Example: On Button click? | import java.awt.*;
import java.awt.event.*;
//1st step
public class ActionListenerExample implements ActionListener{
public static void main(String[] args) {
Frame f=new Frame("ActionListener Example");
final TextField tf=new TextField();
tf.setBounds(50,50, 150,20);
Button b=new... |
Can you provide a Java ActionListener Example: Using Anonymous class? | We can also use the anonymous class to implement the ActionListener. It is the shorthand way, so you do not need to follow the 3 steps:
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tf.setText("Welcome to Javatpoint.");
}
});
Let us see the full code ... |
What is Java MouseListener Interface? | The Java MouseListener is notified whenever you change the state of mouse. It is notified against MouseEvent. The MouseListener interface is found in java.awt.event package. It has five methods. |
What are the Methods of MouseListener interface? | The signature of 5 methods found in MouseListener interface are given below:
public abstract void mouseClicked(MouseEvent e);
public abstract void mouseEntered(MouseEvent e);
public abstract void mouseExited(MouseEvent e);
public abstract void mousePressed(MouseEvent e);
public abstract void mouseRelease... |
Can you provide a Java MouseListener Example? | import java.awt.*;
import java.awt.event.*;
public class MouseListenerExample extends Frame implements MouseListener{
Label l;
MouseListenerExample(){
addMouseListener(this);
l=new Label();
l.setBounds(20,50,100,20);
add(l);
setSize(... |
What is Java MouseMotionListener Interface? | The Java MouseMotionListener is notified whenever you move or drag mouse. It is notified against MouseEvent. The MouseMotionListener interface is found in java.awt.event package. It has two methods. |
What are the Methods of MouseMotionListener interface? | The signature of 2 methods found in MouseMotionListener interface are given below:
public abstract void mouseDragged(MouseEvent e);
public abstract void mouseMoved(MouseEvent e); |
Can you provide a Java MouseMotionListener Example? | import java.awt.*;
import java.awt.event.*;
public class MouseMotionListenerExample extends Frame implements MouseMotionListener{
MouseMotionListenerExample(){
addMouseMotionListener(this);
setSize(300,300);
setLayout(null);
setVisible(true);
}... |
What is Java ItemListener Interface? | The Java ItemListener is notified whenever you click on the checkbox. It is notified against ItemEvent. The ItemListener interface is found in java.awt.event package. It has only one method: itemStateChanged(). |
What is itemStateChanged() method? | The itemStateChanged() method is invoked automatically whenever you click or unclick on the registered checkbox component.
public abstract void itemStateChanged(ItemEvent e); |
Can you provide a Java ItemListener Example? | import java.awt.*;
import java.awt.event.*;
public class ItemListenerExample implements ItemListener{
Checkbox checkBox1,checkBox2;
Label label;
ItemListenerExample(){
Frame f= new Frame("CheckBox Example");
label = new Label();
label.setAl... |
What is Java KeyListener Interface? | The Java KeyListener is notified whenever you change the state of key. It is notified against KeyEvent. The KeyListener interface is found in java.awt.event package, and it has three methods. |
What are the Methods of KeyListener interface? | Methods of KeyListener interface
The signature of 3 methods found in KeyListener interface are given below:
Method name: public abstract void keyPressed (KeyEvent e);
Description: It is invoked when a key has been pressed.
Method name: public abstract void keyReleased (KeyEvent e);
Description: It is invoked w... |
Can you provide a Java KeyListener Example? | In the following example, we are implementing the methods of the KeyListener interface.
KeyListenerExample.java
// importing awt libraries
import java.awt.*;
import java.awt.event.*;
// class which inherits Frame class and implements KeyListener interface
public class KeyListenerExample extends Fr... |
What is Java WindowListener Interface? | The Java WindowListener is notified whenever you change the state of window. It is notified against WindowEvent. The WindowListener interface is found in java.awt.event package. It has three methods. |
What is WindowListener interface declaration? | The declaration for java.awt.event.WindowListener interface is shown below:
public interface WindowListener extends EventListener |
What are the Methods of WindowListener interface? | Methods of WindowListener interface
The signature of 7 methods found in WindowListener interface with their usage are given below:
Method signature: public abstract void windowActivated (WindowEvent e);
Description: It is called when the Window is set to be an active Window.
Method signature: public abstract vo... |
What is Working of WindowListener interface? | -If a class needs to process some Window events, an object should exist which can implement the interface.
-As the object is already registered with Listener, an event will be generated on all the states of window.
-This helps in generation of invocation of relevant method in listener's object. And then WindowEvent is ... |
Can you provide a Java WindowListener Example? | In the following example, we are going to implement all the method of WindowListener interface one by one.
WindowExample.java
// importing necessary libraries of awt
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
// class which inherits Frame class... |
What is Java Adapter Classes? | Java adapter classes provide the default implementation of listener interfaces. If you inherit the adapter class, you will not be forced to provide the implementation of all the methods of listener interfaces. So it saves code. |
What are the Pros of using Adapter classes? | It assists the unrelated classes to work combinedly.
It provides ways to use classes in different ways.
It increases the transparency of classes.
It provides a way to include related patterns in the class.
It provides a pluggable kit for developing an application.
It increases the reusability of the class. |
What is the list of java.awt.event Adapter classes? | Adapter class : WindowAdapter
Listener interface : WindowListener
Adapter class : KeyAdapter
Listener interface : KeyListener
Adapter class : MouseAdapter
Listener interface : MouseListener
Adapter class : MouseMotionAdapter
Listener interface : MouseMotionListener
Adapter class : FocusAdapter
Listener interface... |
What is the list java.awt.dnd Adapter classes? | Adapter class : DragSourceAdapter
Listener interface : DragSourceListener
Adapter class : DragTargetAdapter
Listener interface : DragTargetListener |
What is the list of javax.swing.event Adapter classes? | Adapter class : MouseInputAdapter
Listener interface : MouseInputListener
Adapter class : InternalFrameAdapter
Listener interface : InternalFrameListener |
Can you provide a Java WindowAdapter Example? | // importing the necessary libraries
import java.awt.*;
import java.awt.event.*;
public class AdapterExample {
// object of Frame
Frame f;
// class constructor
AdapterExample() {
// creating a frame with the title
f = new Frame ("Window Adapter");
// adding ... |
Can you provide a Java MouseAdapter Example? | // importing the necessary libraries
import java.awt.*;
import java.awt.event.*;
// class which inherits the MouseAdapter class
public class MouseAdapterExample extends MouseAdapter {
// object of Frame class
Frame f;
// class constructor
MouseAdapterExample() {
// creat... |
Can you provide a Java MouseMotionAdapter Example? | // importing the necessary libraries
import java.awt.*;
import java.awt.event.*;
// class which inherits the MouseMotionAdapter class
public class MouseMotionAdapterExample extends MouseMotionAdapter {
// object of Frame class
Frame f;
// class constructor
MouseMotionAdapterExam... |
Can you provide a Java KeyAdapter Example? | // importing the necessary libraries
import java.awt.*;
import java.awt.event.*;
// class which inherits the KeyAdapter class
public class KeyAdapterExample extends KeyAdapter {
// creating objects of Label, TextArea and Frame
Label l;
TextArea area;
Frame f;
// class ... |
How to close AWT Window in Java? | We can close the AWT Window or Frame by calling dispose() or System.exit() inside windowClosing() method. The windowClosing() method is found in WindowListener interface and WindowAdapter class. |
What are the Different ways to override windowClosing() method? | By anonymous class
By inheriting WindowAdapter class
By implementing WindowListener interface |
Can you provide a Close AWT Window Example 1: Anonymous class? | // importing necessary awt libraries
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
// class which inherits the Frame class
public class WindowExample extends Frame {
// class constructor
WindowExample() {
// adding WindowListener t... |
Can you provide a Close AWT Window Example 2: extending WindowAdapter? | // importing the necessary libraries
import java.awt.*;
import java.awt.event.*;
// class which inherits the WindowAdapter class
public class AdapterExample extends WindowAdapter {
// object of Frame
Frame f;
// class constructor
AdapterExample() {
// creating the frame ... |
What is the Difference between AWT and Swing? | No.1 Java AWT : AWT components are platform-dependent.
Java Swing: Java swing components are platform-independent.
No.2 Java AWT : AWT components are heavyweight.
Java Swing: Swing components are lightweight.
No.3 Java AWT : AWT doesn't support pluggable look and feel.
Java Swing: Swing supports pluggable look an... |
What is JFC? | The Java Foundation Classes (JFC) are a set of GUI components which simplify the development of desktop applications. |
What are the Commonly used Methods of Component class? | Method: public void add(Component c)
Description: add a component on another component.
Method: public void setSize(int width,int height)
Description: sets size of the component.
Method: public void setLayout(LayoutManager m)
Description: sets the layout manager for the component.
Method: public void setVisible(b... |
What is Java JButton? | The JButton class is used to create a labeled button that has platform independent implementation. The application result in some action when the button is pushed. It inherits AbstractButton class. |
What is JButton class declaration? | public class JButton extends AbstractButton implements Accessible |
What are the Commonly used Constructors:? | Constructor: JButton()
Description: It creates a button with no text and icon.
Constructor: JButton(String s)
Description: It creates a button with the specified text.
Constructor: JButton(Icon i)
Description: It creates a button with the specified icon object.
|
What are the Commonly used Methods of AbstractButton class? | Methods: void setText(String s)
Description: It is used to set specified text on button
Methods: String getText()
Description: It is used to return the text of the button.
Methods: void setEnabled(boolean b)
Description: It is used to enable or disable the button.
Methods: void setIcon(Icon b)
Description: It is... |
Can you provide a Java JButton Example? | import java.awt.event.*;
import javax.swing.*;
public class ButtonExample {
public static void main(String[] args) {
JFrame f=new JFrame("Button Example");
final JTextField tf=new JTextField();
tf.setBounds(50,50, 150,20);
JButton b=new JButton("Click Here");
b.setBounds(50... |
Can you provide a Java JButton Example with ActionListener? | import java.awt.event.*;
import javax.swing.*;
public class ButtonExample {
public static void main(String[] args) {
JFrame f=new JFrame("Button Example");
final JTextField tf=new JTextField();
tf.setBounds(50,50, 150,20);
JButton b=new JButton("Click Here");
b.setBounds(50... |
Can you provide an Example of displaying image on the button? | import javax.swing.*;
public class ButtonExample{
ButtonExample(){
JFrame f=new JFrame("Button Example");
JButton b=new JButton(new ImageIcon("D:\\icon.png"));
b.setBounds(100,100,100, 40);
f.add(b);
f.setSize(300,400);
f.setLayout(null);
f.setVisible(true);
f... |
What is Java JLabel? | The object of JLabel class is a component for placing text in a container. It is used to display a single line of read only text. The text can be changed by an application but a user cannot edit it directly. It inherits JComponent class. |
What is JLabel class declaration? | public class JLabel extends JComponent implements SwingConstants, Accessible |
Can you provide a Java JLabel Example? | import javax.swing.*;
class LabelExample
{
public static void main(String args[])
{
JFrame f= new JFrame("Label Example");
JLabel l1,l2;
l1=new JLabel("First Label.");
l1.setBounds(50,50, 100,30);
l2=new JLabel("Second Label.");
l2.setBounds(50,100, 100,30);
... |
Can you provide a Java JLabel Example with ActionListener? | import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class LabelExample extends Frame implements ActionListener{
JTextField tf; JLabel l; JButton b;
LabelExample(){
tf=new JTextField();
tf.setBounds(50,50, 150,20);
l=new JLabel();
l.... |
What is Java JTextField? | The object of a JTextField class is a text component that allows the editing of a single line text. It inherits JTextComponent class. |
What is JTextField class declaration? | public class JTextField extends JTextComponent implements SwingConstants |
Can you provide a Java JTextField Example? | import javax.swing.*;
class TextFieldExample
{
public static void main(String args[])
{
JFrame f= new JFrame("TextField Example");
JTextField t1,t2;
t1=new JTextField("Welcome to Javatpoint.");
t1.setBounds(50,100, 200,30);
t2=new JTextField("AWT Tutorial");
t2.... |
Can you provide a Java JTextField Example with ActionListener? | import javax.swing.*;
import java.awt.event.*;
public class TextFieldExample implements ActionListener{
JTextField tf1,tf2,tf3;
JButton b1,b2;
TextFieldExample(){
JFrame f= new JFrame();
tf1=new JTextField();
tf1.setBounds(50,50,150,20);
tf2=new JTe... |
What is Java JTextArea? | The object of a JTextArea class is a multi line region that displays text. It allows the editing of multiple line text. It inherits JTextComponent class |
What is JTextArea class declaration? | public class JTextArea extends JTextComponent |
Can you provide a Java JTextArea Example? | import javax.swing.*;
public class TextAreaExample
{
TextAreaExample(){
JFrame f= new JFrame();
JTextArea area=new JTextArea("Welcome to javatpoint");
area.setBounds(10,30, 200,200);
f.add(area);
f.setSize(300,300);
f.setLayout(null);
... |
Can you provide a Java JTextArea Example with ActionListener? | import javax.swing.*;
import java.awt.event.*;
public class TextAreaExample implements ActionListener{
JLabel l1,l2;
JTextArea area;
JButton b;
TextAreaExample() {
JFrame f= new JFrame();
l1=new JLabel();
l1.setBounds(50,25,100,30);
l2=new JLabel();
l2.setBounds(160,... |
What is JLabel class declaration? | public class JLabel extends JComponent implements SwingConstants, Accessible |
What is JPasswordField class declaration? | public class JPasswordField extends JTextField |
Can you provide a Java JPasswordField Example? | import javax.swing.*;
public class PasswordFieldExample {
public static void main(String[] args) {
JFrame f=new JFrame("Password Field Example");
JPasswordField value = new JPasswordField();
JLabel l1=new JLabel("Password:");
l1.setBounds(20,100, 80,30);
... |
Can you provide a Java JPasswordField Example with ActionListener? | import javax.swing.*;
import java.awt.event.*;
public class PasswordFieldExample {
public static void main(String[] args) {
JFrame f=new JFrame("Password Field Example");
final JLabel label = new JLabel();
label.setBounds(20,150, 200,50);
final JPasswordField ... |
What is Java JCheckBox? | The JCheckBox class is used to create a checkbox. It is used to turn an option on (true) or off (false). Clicking on a CheckBox changes its state from "on" to "off" or from "off" to "on ".It inherits JToggleButton class. |
What is JCheckBox class declaration? | public class JCheckBox extends JToggleButton implements Accessible |
Can you provide a Java JCheckBox Example? | import javax.swing.*;
public class CheckBoxExample
{
CheckBoxExample(){
JFrame f= new JFrame("CheckBox Example");
JCheckBox checkBox1 = new JCheckBox("C++");
checkBox1.setBounds(100,100, 50,50);
JCheckBox checkBox2 = new JCheckBox("Java", true);
check... |
Can you provide a Java JCheckBox Example with ItemListener? | import javax.swing.*;
import java.awt.event.*;
public class CheckBoxExample
{
CheckBoxExample(){
JFrame f= new JFrame("CheckBox Example");
final JLabel label = new JLabel();
label.setHorizontalAlignment(JLabel.CENTER);
label.setSize(400,... |
What is Java JRadioButton? | The JRadioButton class is used to create a radio button. It is used to choose one option from multiple options. It is widely used in exam systems or quiz.
It should be added in ButtonGroup to select one radio button only. |
What is JRadioButton class declaration? | public class JRadioButton extends JToggleButton implements Accessible |
Can you provide a Java JRadioButton Example? | import javax.swing.*;
public class RadioButtonExample {
JFrame f;
RadioButtonExample(){
f=new JFrame();
JRadioButton r1=new JRadioButton("A) Male");
JRadioButton r2=new JRadioButton("B) Female");
r1.setBounds(75,50,100,30);
r2.setBounds(75,100,100,30);
ButtonGroup bg=new Bu... |
Can you provide a Java JRadioButton Example with ActionListener? | import javax.swing.*;
import java.awt.event.*;
class RadioButtonExample extends JFrame implements ActionListener{
JRadioButton rb1,rb2;
JButton b;
RadioButtonExample(){
rb1=new JRadioButton("Male");
rb1.setBounds(100,50,100,30);
rb2=new JRadioButton("Female");
rb2.setBou... |
What is Java JComboBox? | The object of Choice class is used to show popup menu of choices. Choice selected by user is shown on the top of a menu. It inherits JComponent class. |
What is JComboBox class declaration? | public class JComboBox extends JComponent implements ItemSelectable, ListDataListener, ActionListener, Accessible |
Can you provide an Example of Java JComboBox? | import javax.swing.*;
public class ComboBoxExample {
JFrame f;
ComboBoxExample(){
f=new JFrame("ComboBox Example");
String country[]={"India","Aus","U.S.A","England","Newzealand"};
JComboBox cb=new JComboBox(country);
cb.setBounds(50, 50,90,20);
f.add(cb);... |
Can you provide a Java JComboBox Example with ActionListener? | import javax.swing.*;
import java.awt.event.*;
public class ComboBoxExample {
JFrame f;
ComboBoxExample(){
f=new JFrame("ComboBox Example");
final JLabel label = new JLabel();
label.setHorizontalAlignment(JLabel.CENTER);
label.setSize(400,100);
JButton b... |
What is Java JTable? | The JTable class is used to display data in tabular form. It is composed of rows and columns. |
What is JTable class declaration? | Constructor: JTable()
Description: Creates a table with empty cells.
Constructor: JTable(Object[][] rows, Object[] columns)
Description: Creates a table with the specified data.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.