Question

Lab - 0 X Enter a word HELLO Enter HELLO Courier O Red Arial Green Blue Multiple check boxes can be checked at the same time,

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
public class Q1 extends JFrame {

   public static void createAndShowGUI() {
       JFrame frame = new JFrame("Q1");
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       Font courierFont = new Font("Courier", Font.BOLD, 40);
       Font arialFont = new Font("Arial", Font.BOLD, 40);
       Font sansFont = new Font("Sans-serif", Font.BOLD, 20);
       JLabel label = new JLabel("Enter a word"); label.setFont(sansFont);
       Font font1 = new Font("Sans-serif", Font.BOLD, 40);
       JLabel label1 = new JLabel("HELLO"); label1.setFont(font1);
       JTextField textField = new JTextField(10); textField.setText("HELLO"); textField.setFont(sansFont);
       JButton button = new JButton("Enter"); button.setFont(sansFont);
       JCheckBox checkboxCourier = new JCheckBox("Courier"); checkboxCourier.setFont(courierFont);
       JCheckBox checkboxArial = new JCheckBox("Arial"); checkboxArial.setFont(arialFont);
       Font font2 = new Font("Sans-serif", Font.ITALIC, 15);
       JRadioButton radioButtonRed = new JRadioButton("Red"); radioButtonRed.setFont(font2);
       JRadioButton radioButtonGreen = new JRadioButton("Green"); radioButtonGreen.setFont(font2);
       JRadioButton radioButtonBlue = new JRadioButton("Blue"); radioButtonBlue.setFont(font2);

       JPanel topPanel = new JPanel();
       topPanel.add(label);
       topPanel.add(textField);
       topPanel.add(button);
       topPanel.add(label1);
       JPanel checkBoxPanel = new JPanel(); checkBoxPanel.setLayout(new GridBagLayout());
       GridBagConstraints c1 = new GridBagConstraints(); c1.gridx = 0; c1.gridy = GridBagConstraints.RELATIVE; c1.anchor = GridBagConstraints.WEST;
       checkBoxPanel.add(checkboxCourier, c1);
       checkBoxPanel.add(checkboxArial, c1);

       JPanel bottomPanel = new JPanel();
       JPanel radioButtonPanel = new JPanel(); radioButtonPanel.setLayout(new GridBagLayout());
       GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = GridBagConstraints.RELATIVE; c.anchor = GridBagConstraints.WEST;
       radioButtonPanel.add(radioButtonRed, c);
       radioButtonPanel.add(radioButtonGreen, c);
       radioButtonPanel.add(radioButtonBlue, c);
       bottomPanel.add(checkBoxPanel);
       bottomPanel.add(radioButtonPanel);

       //ButtonGroup needs to be completed

       JPanel middlePanel = new JPanel();
       middlePanel.add(label1);

  frame.setLayout(new FlowLayout());
       frame.getContentPane().add(topPanel);
       frame.getContentPane().add(middlePanel);
       frame.getContentPane().add(bottomPanel);

       frame.setSize(420, 300);
       frame.setVisible(true);
       button.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent event) {
               String word = textField.getText(); label1.setText(word);
           }
       });
       textField.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent event) {
               String word = textField.getText(); label1.setText(word);
           }
       });
       radioButtonGreen.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent event) {

           }
       });
       radioButtonBlue.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent event) {

           }
       });
  checkboxArial.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent event) {

           }
       });
   }

   public static void main(String[] args) {
    javax.swing.SwingUtilities.
invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
   }
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
public class Q1 extends JFrame implements ItemListener,ActionListener{

   public static void createAndShowGUI() {
       JFrame frame = new JFrame("Q1");
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       Font courierFont = new Font("Courier", Font.BOLD, 40);
       Font arialFont = new Font("Arial", Font.BOLD, 40);
       Font sansFont = new Font("Sans-serif", Font.BOLD, 20);
       JLabel label = new JLabel("Enter a word"); label.setFont(sansFont);
       Font font1 = new Font("Sans-serif", Font.BOLD, 40);
       JLabel label1 = new JLabel("HELLO"); label1.setFont(font1);
       JTextField textField = new JTextField(10); textField.setText("HELLO"); textField.setFont(sansFont);
       JButton button = new JButton("Enter"); button.setFont(sansFont);
     
       JCheckBox checkboxCourier = new JCheckBox("Courier"); checkboxCourier.setFont(courierFont);
       JCheckBox checkboxArial = new JCheckBox("Arial"); checkboxArial.setFont(arialFont);
     
       Font font2 = new Font("Sans-serif", Font.ITALIC, 15);
     
       JRadioButton radioButtonRed = new JRadioButton("Red"); radioButtonRed.setFont(font2);
       JRadioButton radioButtonGreen = new JRadioButton("Green"); radioButtonGreen.setFont(font2);
       JRadioButton radioButtonBlue = new JRadioButton("Blue"); radioButtonBlue.setFont(font2);

   //Button group added

       ButtonGroup bg=new ButtonGroup();  
       bg.add(radioButtonRed);bg.add(radioButtonGreen););bg.add(radioButtonBlue);
      
       JPanel topPanel = new JPanel();
       topPanel.add(label);
       topPanel.add(textField);
       topPanel.add(button);
       topPanel.add(label1);
       JPanel checkBoxPanel = new JPanel(); checkBoxPanel.setLayout(new GridBagLayout());
       GridBagConstraints c1 = new GridBagConstraints(); c1.gridx = 0; c1.gridy = GridBagConstraints.RELATIVE; c1.anchor = GridBagConstraints.WEST;
       checkBoxPanel.add(checkboxCourier, c1);
       checkBoxPanel.add(checkboxArial, c1);

       JPanel bottomPanel = new JPanel();
       JPanel radioButtonPanel = new JPanel(); radioButtonPanel.setLayout(new GridBagLayout());
       GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = GridBagConstraints.RELATIVE; c.anchor = GridBagConstraints.WEST;
       radioButtonPanel.add(radioButtonRed, c);
       radioButtonPanel.add(radioButtonGreen, c);
       radioButtonPanel.add(radioButtonBlue, c);
       bottomPanel.add(checkBoxPanel);
       bottomPanel.add(radioButtonPanel);

       //ButtonGroup needs to be completed

       JPanel middlePanel = new JPanel();
       middlePanel.add(label1);

frame.setLayout(new FlowLayout());
       frame.getContentPane().add(topPanel);
       frame.getContentPane().add(middlePanel);
       frame.getContentPane().add(bottomPanel);

       frame.setSize(420, 300);
       frame.setVisible(true);
       checkboxCourier.addItemListener(this);
        checkboxArial.addItemListener(this);
      
       button.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent event) {
               String word = textField.getText(); label1.setText(word);
           }
       });
       textField.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent event) {
               String word = textField.getText(); label1.setText(word);
           }
       });
       radioButtonGreen.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent event) {

           }


       });
       radioButtonBlue.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent event) {

           }
       });
checkboxArial.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent event) {

           }
       });
   }
   //for checkbox group
    public void itemStateChanged(ItemEvent eve)
    {
        if(checkboxCourier.isSelected())
        {
          
            checkboxCourier.setSelected(false);
        }
        else if(checkboxArial.isSelected())
        {
         
            checkboxArial.setSelected(false);
        }
     
    }

   public static void main(String[] args) {
    javax.swing.SwingUtilities.
invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
   }
}

Add a comment
Know the answer?
Add Answer to:
import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.BorderFactory; import javax.swing.border.Border; public class Q1 extends JFrame {...
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...

  • import javax.swing.*; import java.awt.event.*; import java.awt.*; public class BookReview extends JFrame implements ActionListener {       private JLabel...

    import javax.swing.*; import java.awt.event.*; import java.awt.*; public class BookReview extends JFrame implements ActionListener {       private JLabel titleLabel;       private JTextField titleTxtFd;       private JComboBox typeCmb;       private ButtonGroup ratingGP;       private JButton processBnt;       private JButton endBnt;       private JButton clearBnt;       private JTextArea entriesTxtAr;       private JRadioButton excellentRdBnt;       private JRadioButton veryGoodRdBnt;       private JRadioButton fairRdBnt;       private JRadioButton poorRdBnt;       private String ratingString;       private final String EXCELLENT = "Excellent";       private final String VERYGOOD = "Very Good";       private final String FAIR = "Fair";       private final String POOR = "Poor";       String...

  • There 2 parts to complete: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class Q4 extends JFrame...

    There 2 parts to complete: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class Q4 extends JFrame { private int xPos, yPos; public Q4() { JPanel drawPanel = new JPanel() { @Override public void paintComponent(Graphics g) { super.paintComponent(g); // paint parent's background //complete this: } }; drawPanel.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { //complete this :- set the xPos, yPos }    }); setContentPane(drawPanel); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("Mouse-Click Demo"); setSize(400, 250); setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() {...

  • This is all I have regarding the question import java.awt.*; import java.awt.event.*; import javax.swing.*; public class...

    This is all I have regarding the question import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Quiz8_GUI { private JFrame frame;    /** * Create an Quiz8_GUI show it on screen. */ public Quiz8_GUI() { makeFrame(); } // ---- swing stuff to build the frame and all its components ---- /** * Create the Swing frame and its content. */ private void makeFrame() { frame = new JFrame("Quiz8_GUI"); makeMenuBar(frame); Container contentPane = frame.getContentPane(); //set the Container to flow layout //Your...

  • Can you please fix the error. package com.IST240Apps; import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*;...

    Can you please fix the error. package com.IST240Apps; import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*; import java.net.*; public class LinkRotator extends JFrame implements Runnable, ActionListener { String[] pageTitle = new String[5]; URI[] pageLink = new URI[5]; int current = 0; Thread runner; JLabel siteLabel = new Jlabel(); public LinkRotator() { setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE); setSize(300, 100); FlowLayout flo = new Flowlayout(); setLayout(flo); add(siteLabel); pageTitle = new String[] { "Oracle Java Site", "Server Side", "JavaWorld", "Google", "Yahoo", "Penn State" }; pageLink[0] = getUR1("http://www.oracle.com/technetwork/java");...

  • I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label;...

    I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label; import java.awt.TextArea; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Fall_2017 {    public TextArea courseInput;    public Label textAreaLabel;    public JButton addData;    public Dialog confirmDialog;    HashMap<Integer, ArrayList<String>> students;    public Fall_2017(){    courseInput = new TextArea(20, 40);    textAreaLabel = new Label("Student's data:");    addData = new JButton("Add...

  • Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import...

    Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class translatorApp extends JFrame implements ActionListener {    public static final int width = 500;    public static final int height = 300;    public static final int no_of_lines = 10;    public static final int chars_per_line = 20;    private JTextArea lan1;    private JTextArea lan2;    public static void main(String[] args){        translatorApp gui = new translatorApp();...

  • How can i make the java class seperate into an MVC pattern? public class ChatView implements Acti...

    How can i make the java class seperate into an MVC pattern? public class ChatView implements ActionListener {    public static void main(String[] args)    {        JFrame chatFrame = new JFrame();        JFrame chatFrame1 = new JFrame();        JFrame chatFrame2 = new JFrame();               JPanel chatPanel = new JPanel();        JPanel chatPanel1 = new JPanel();        JPanel chatPanel2 = new JPanel();        chatFrame.setContentPane(chatPanel);        chatFrame1.setContentPane(chatPanel1);        chatFrame2.setContentPane(chatPanel2);        chatFrame.setLayout(new FlowLayout());        chatFrame1.setLayout(new FlowLayout());        chatFrame2.setLayout(new FlowLayout());        JTextField chatWrite = new JTextField();        JTextField chatWrite1 = new JTextField();        JTextField chatWrite2 = new JTextField();        JTextArea chatDisplay...

  • Debug this java and post the corrected code. /* Creates a simple JPanel with a single...

    Debug this java and post the corrected code. /* Creates a simple JPanel with a single "quit" JButton * that ends the program when clicked. * There are 3 errors, one won't prevent compile, you have to read comments. */ import javax.swing.*; import java.awt.*; import java.awt.event.*; public class QuitIt extends JFrame {     public QuitIt() {         startIt(); //Create everything and start the listener     }     public final void startIt() {        //Create the JPanel        JPanel myPanel =...

  • Add a timer to the lightbulb ON/OFF program such that the bulb stays on for 10...

    Add a timer to the lightbulb ON/OFF program such that the bulb stays on for 10 seconds after the ON button is pushed and then goes off.   Put a new label on the lightbulb panel that counts the number of seconds the bulb is on and displays the number of seconds as it counts up from 0 to 10. THIS IS A JAVA PROGRAM. The image above is what it should look like. // Demonstrates mnemonics and tool tips. //********************************************************************...

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