Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write an application that has size 300 by 300. Put 2 RadioButtons on the appl

ID: 641228 • Letter: 1

Question

1. Write an application that has size 300 by 300. Put 2 RadioButtons on the application. One has text "BLUE" and the other has text "RED" . When the "RED" one is selected the background turns red . If the "BLUE" one is selected the background turns blue.

2. Write an application that has size 400 by 400. It has a textField and a button with the text "PRESS" on it. When text is put on the TextField and the button is pressesd the text in the textField disappears.

3. Write an application that has size 250 by 250. It has two buttons labeled "ONE" and "TWO".
If button labeled "ONE" is selected then the Word "ONE" is printed on the Console Screen.
If button labeled "TWO" is selected then the Word "TWO" is printed on the Console Screen.

4. Write an application that has the Layout BorderLayout. This will only use CENTER and SOUTH.
The SOUTH part will have 2 buttons labeled "WHITE" and "BLACK". If a button is selected the CENTER part changes to the color indicated.


5. Write an application that has size 300 by 300. When the mouse is over the application, the background turns red. When it leaves, it turns blue.

Explanation / Answer

For the Questions above I have used programming concepts of java netbeans:

Q.1. Program to show the use of RadioButtons:

Steps:

1. To set the size of the form, open java jFrame form and set the form properties. Set preferredSize property to [300,300]

2. Select RadioButtons from the toolbox and place it on the form. Select jRadioButton1 and set its text property to "Blue" and then select jRadioButton2 and set its text property to "Red".

3. Write following code:

private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt)

{   
   
  getContentPane().setBackground(java.awt.Color.blue);

}

private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt)
{
getContentPane().setBackground(java.awt.Color.red);
}

__________________________________________________________________________________________________________________________________________________________

Q.2. Program to show the use of TextField and Buttons:

Steps:

1. To set the size of the form, open java jFrame form and set the form properties. Set preferredSize property to [400,400]

2. Select jTextField1 and jButton1 from the toolbox and place it on the form. Select jButton1 and set its text property to "PRESS"

3. Write following code:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)   
{
jTextField1.setText("");
}

___________________________________________________________________________________________________________________________________________________________

  Q.3. Program to show the use of Buttons:

Steps:

1. To set the size of the form, open java jFrame form and set the form properties. Set preferredSize property to [250,250]

2. Select jButtons from the toolbox and place it on the form. Select jButton1 and set its text property to "ONE" and select jButton2 and set its text property to "TWO"

3. Write following code:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)     
{
JOptionPane.showMessageDialog(null,"ONE");
}

NOTE: If error comes in JOptionPane then select yellow bulb on the left and select add import for javax.swing.JOptionPane. This will import a file to the source code.

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)     
{
JOptionPane.showMessageDialog(null,"TWO");
}   

________________________________________________________________________________________________________________________________________________________________

  Q.4. Program to show the use of BorderLayout:

JPanel pan1 = new JPanel();
pan1.setLayout(new BorderLayout());
JPanel addp = new JPanel();
pan1.add(addp, BorderLayout.CENTER);

JPanel pan2 = new JPanel();
pan2.setLayout(new BorderLayout());
JPanel addpa = new JPanel();
pan2.add(addpa, BorderLayout.SOUTH);

_________________________________________________________________________________________________________________________________________________________

Q.5. Program to show the use of Rollover Buttons:

Steps:

1. To set the size of the form, open java jFrame form and set the form properties. Set preferredSize property to [400,400]

2. Select jButton1 from the toolbox and place it on the form.

3. Select the jButton and set its rolloverIcon property. Select External image option and import the image you want as rollover image.

4. Run the application to see the result. When you will take your mouse over the button, the image will be displayed.