Adv Java - [Swing: JButton Class]

♠ Posted by Unknown in

Swing Button Classes


Swing buttons provide features that are not found in the Button class defined by the AWT. For example, you can associate an icon with a Swing button. Swing buttons are subclasses of the AbstractButton class, which extends JComponent. AbstractButton contains many methods that allow you to control the behavior of buttons, check boxes, and radio buttons.

Adv Java - [Swing JTextField Class]

♠ Posted by Unknown in

JTextField Class


The swing text field is encapsulated by the JTextComponent class, which extends JComponent. It provides functionality that is common to Swing text components. One of its subclass is JTextField, which allows you to edit one line of text.

Adv Java - [Swing: ImageIcon/JLabel Classes]

♠ Posted by Unknown in

ImageIcon Class


In Swing, icons are encapsulated by the ImageIcon class, which paints an icon from an image. Two of lists constructors are show here:

     ImageIcon(String filename)
     ImageIcon(URL url)

The first form used the image in the file named “filename”. The second form used the image in the resource identified by “url”.

Adv Java - [Swing Layout Manager]

♠ Posted by Unknown in

Layout Managers


The way that you place components on a form in Java is probably different from any other GUI system you’ve used. The way components are placed on a form is controlled not by absolute positioning but by a “Layout Manager” that decides how the components lie based on the order that you add() them. The size, shape, and placement of components will be remarkably different from one layout manager to another. In addition, the layout managers adapt to the dimensions of your applet or application window, so if the window dimension is changed, the size, shape, and placement of the components can change in response.

Adv Java - [Swing Fundamental]

♠ Posted by Unknown in

swing


Swing is a set of classes that provides more powerful and flexible components than are possible with the AWT. In addition to the familiar components, such as buttons, check boxes, and labels, Swings supplies several exciting addition, including tabbed panes, scroll panes, trees, and tables. Even familiar components such as buttons have more capabilities in swing. For example, a button may have both an image and a text string associated with it. Also, the image can be changed as the state of the button changes.

Core Java - [Java File Handling]

♠ Posted by Unknown in

Java Stream Classes


The java.io package a large number of stream classes that provide capabilities for processing all types of data. These classes may be categorized into two groups on the data type on which they operate.

Core Java - [AWT GridLayout [Frame] Example]

♠ Posted by Unknown in
GridLayout  Manager on Frame

Example:


import java.awt.*;
import java.awt.event.*;

class FindHighestExample extends Frame implements ActionListener
{
    Label lblFirst, lblSecond, lblThird, lblAnswer;
    TextField tfFirst, tfSecond, tfThird;
    Button btnCheck, btnClear, btnExit;
    Panel p1, p2;

    public FindHighestExample()
    {
        lblFirst = new Label("Enter First Value : ");
        lblSecond = new Label("Enter Second Value : ");
        lblThird = new Label("Enter Third Value : ");
        lblAnswer = new Label("The Highest : ");

        tfFirst = new TextField("0");
        tfSecond = new TextField("0");
        tfThird = new TextField("0");

        btnCheck = new Button("Check");
        btnClear = new Button("Clear");
        btnExit = new Button("Exit");

        setLayout(new FlowLayout());
        p1 = new Panel();
        p1.setLayout(new GridLayout(4,2,5,10));

        p2 = new Panel();
        p2.setLayout(new FlowLayout(FlowLayout.CENTER,5,10));

        add(p1);
        add(p2);

        p1.add(lblFirst);
        p1.add(tfFirst);
        p1.add(lblSecond);
        p1.add(tfSecond);
        p1.add(lblThird);
        p1.add(tfThird);
        p1.add(lblAnswer);

        p2.add(btnCheck);
        btnCheck.addActionListener(this);
        p2.add(btnClear);
        btnClear.addActionListener(this);
        p2.add(btnExit);
        btnExit.addActionListener(this);
    }

    public void actionPerformed(ActionEvent ae)
    {
        if(ae.getSource() == btnCheck)
        {
                int a, b, c;
                a = Integer.parseInt(tfFirst.getText());
                b = Integer.parseInt(tfSecond.getText());
                c = Integer.parseInt(tfThird.getText());

                if((a>b) && (a>c))
                {
                        lblAnswer.setText("The Highest : " + a);
                }
                else if(b>c)
                {
                        lblAnswer.setText("The Highest : " + b);
                }
                else
                {
                        lblAnswer.setText("The Highest : " + c);
                }
        }
        else if(ae.getSource() == btnClear)
        {
                tfFirst.setText("0");
                tfSecond.setText("0");
                tfThird.setText("0");

        }
        else
        {
                dispose();
                System.exit(0);
        }
    }

    public static void main(String[] args) 
    {
        FindHighestExample f = new FindHighestExample();
        f.setVisible(true);
        f.setSize(400,200);
    }

}