NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package hw1;

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

import javax.swing.*;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;

public class Homework4 extends JFrame implements ActionListener {
private JComboBox<String> cb;
private JRadioButton r1, r2, r3, r4;
private ButtonGroup bg;
private JCheckBox ch1, ch2, ch3, ch4, ch5, ch6;
private JButton b1, b2;
private JLabel lb1, lb2, lb3;
private JTextArea tf;
private String[] String = { "1", "2", "3", "4" };

public Homework4() {
// TODO Auto-generated constructor stub

cb = new JComboBox<>(String);
cb.setBounds(120, 20, 90, 20);
this.add(cb);


lb1 = new JLabel("Grade");
lb1.setBounds(20, 20, 70, 20);
this.add(lb1);
lb2 = new JLabel("Department");
lb2.setBounds(20, 60, 70, 20);
this.add(lb2);
lb3 = new JLabel("Cources");
lb3.setBounds(20, 100, 70, 20);
this.add(lb3);


r1 = new JRadioButton("MM");
r2 = new JRadioButton("CS");
r3 = new JRadioButton("IC");
r4 = new JRadioButton("EE");
r1.setBounds(120, 60, 50, 20);
r2.setBounds(180, 60, 50, 20);
r3.setBounds(240, 60, 50, 20);
r4.setBounds(300, 60, 50, 20);
this.add(r1);
this.add(r2);
this.add(r3);
this.add(r4);

ch1 = new JCheckBox("JAVA");
ch1.setBounds(120, 100, 100, 20);
this.add(ch1);
ch2 = new JCheckBox("Network");
ch2.setBounds(230, 100, 100, 20);
this.add(ch2);
ch3 = new JCheckBox("Web design");
ch3.setBounds(120, 140, 100, 20);
this.add(ch3);
ch4 = new JCheckBox("Security");
ch4.setBounds(230, 140, 100, 20);
this.add(ch4);
ch5 = new JCheckBox("C++");
ch5.setBounds(120, 180, 100, 20);
this.add(ch5);
ch6 = new JCheckBox("Circuit");
ch6.setBounds(230, 180, 100, 20);
this.add(ch6);

// button
b1 = new JButton("Show");
b1.setBounds(145, 220, 70, 20);
this.add(b1);
b2 = new JButton("Clear");
b2.setBounds(230, 220, 70, 20);
this.add(b2);

// buttongroup
bg = new ButtonGroup();
bg.add(r1);
bg.add(r2);
bg.add(r3);
bg.add(r4);

// textfield
tf = new JTextArea();
tf.setBounds(10, 260, 500, 180);
this.add(tf);

// actionListener
r1.addActionListener(this);
r2.addActionListener(this);
r3.addActionListener(this);
r4.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
ch1.addActionListener(this);
ch2.addActionListener(this);
ch3.addActionListener(this);
ch4.addActionListener(this);
ch5.addActionListener(this);
ch6.addActionListener(this);
cb.addActionListener(this);

this.setTitle("Form");
this.setLayout(null);
this.setSize(550, 500);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

String grade = "You are Freshman";
String dep;

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getSource() == cb) {
if (cb.getSelectedIndex() == 0) {
grade = "You are Freshman";
} else if (cb.getSelectedIndex() == 1) {
grade = "You are Sophomore";
} else if (cb.getSelectedIndex() == 2) {
grade = "You are Junior";
} else if (cb.getSelectedIndex() == 3) {
grade = "You are Senior";
}
}

if (e.getSource() == r1) {
dep = r1.getText();
}
if (e.getSource() == r2) {
dep = r2.getText();
}
if (e.getSource() == r3) {
dep = r3.getText();
}
if (e.getSource() == r4) {
dep = r4.getText();

}
if (e.getSource() == b1) {
tf.setText("");
tf.append(grade + " in " + dep + ".n");
tf.append("You selected following courses: ");

if (ch1.isSelected() == true) {
tf.append(ch1.getText() + ", ");
}

if (ch2.isSelected() == true) {
tf.append(ch2.getText() + ", ");
}
if (ch3.isSelected() == true) {
tf.append(ch3.getText() + ", ");
}
if (ch4.isSelected() == true) {
tf.append(ch4.getText() + ", ");
}
if (ch5.isSelected() == true) {
tf.append(ch5.getText() + ", ");
}
if (ch6.isSelected() == true) {
tf.append(ch6.getText() + ", ");
}
Document doc = tf.getDocument();
try {
doc.remove(doc.getLength() - 2, 1);
} catch (BadLocationException e1) {
e1.printStackTrace();
}
}
if (e.getSource() == b2) {
tf.setText("");
ch1.setSelected(false);
ch2.setSelected(false);
ch3.setSelected(false);
ch4.setSelected(false);
ch5.setSelected(false);
ch6.setSelected(false);
cb.setSelectedIndex(0);
bg.clearSelection();
}
}

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.