
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();
}
});
}
}
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();
}
});
}
}
import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.BorderFactory; import javax.swing.border.Border; public class Q1 extends JFrame {...
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...
package timing; import java.awt.event.*; import javax.swing.*; public class Timing implements ActionListener{ JButton button1; JLabel label1; public int minutes=3;//initial time public int time=minutes*60;//total amount of time in seconds only public int seconds=time%60; public String defaulttimeset="0"+Integer.toString(minutes)+":0"+Integer.toString(seconds); public static void main(String[] args) { Timing move=new Timing(); move.go(); } public void go(){ JFrame frame=new JFrame(); frame.setBounds(50,50,400,400); JPanel panel2=new JPanel(); button1=new JButton("Start Time"); panel2.add(button1); button1.setBounds(30,50,150,170); frame.getContentPane().add(button1);...
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 { 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 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.*; 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;
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 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();...
Can you fix my error? I created a program that changes labels every second in Java. But, it does not change. And, it will starts with second label. This is also an error. import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.Timer; public class Map2 extends JFrame{ JPanel panel; JLabel pic; Timer tm; int x = 0; String ly = "<html> " + "<br> <font size='10' color='red'> <b> 111111111 <b/> </font>...
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...