- JTable
import javax.swing.*;
import java.awt.*;
class FrameTabel extends JFrame {
String[] header = { "Senin", "Selasa", "Rabu" };
String[][] data = { { "100", "300", "150" }, { "500", "600", "450" },
{ "290", "690", "360" } };
JTable tabel1 = new JTable(data, header);
FrameTabel() {
setLocation(200, 100);
setSize(300, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void KomponenVisual() {
getContentPane().add(tabel1);
setVisible(true);
}
}
class tabel {
public static void main(String args[])
{
FrameTabel t = new FrameTabel();
t.KomponenVisual();
}
}
|
- · JComboBox
import javax.swing.*;
class combobox extends JFrame {
JLabel lblnim = new JLabel("NIM ");
JTextField txnim = new JTextField(20);
JLabel lblnama = new JLabel("Nama");
JTextField txnama = new JTextField(20);
JButton tblcari = new JButton("Cari");
JLabel lblkelas = new JLabel("Kelas ");
JRadioButton kelasA = new JRadioButton("A");
JRadioButton kelasB = new JRadioButton("B");
JRadioButton kelasC = new JRadioButton("C");
ButtonGroup grupkelas = new ButtonGroup();
JLabel lblkelompok = new JLabel("Kelompok");
String[] jeniskelompok = { "1", "2", "3", "4", "5", "6", "7" };
JComboBox cbkelompok = new JComboBox(jeniskelompok);
combobox() {
setTitle("Lembar Penilaian");
setLocation(300, 100);
setSize(300, 150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void komponenVisual() {
getContentPane().setLayout(null);
getContentPane().add(lblnim);
lblnim.setBounds(10, 10, 70, 20);
getContentPane().add(txnim);
txnim.setBounds(75, 10, 100, 20);
getContentPane().add(tblcari);
tblcari.setBounds(180, 10, 95, 20);
getContentPane().add(lblnama);
lblnama.setBounds(10, 30, 70, 20);
getContentPane().add(txnama);
txnama.setBounds(75, 30, 200, 20);
getContentPane().add(lblkelas);
lblkelas.setBounds(10, 50, 100, 20);
getContentPane().add(kelasA);
kelasA.setBounds(75, 50, 50, 20);
getContentPane().add(kelasB);
kelasB.setBounds(125, 50, 50, 20);
getContentPane().add(kelasC);
kelasC.setBounds(175, 50, 50, 20);
grupkelas.add(kelasA);
grupkelas.add(kelasB);
grupkelas.add(kelasC);
getContentPane().add(lblkelompok);
lblkelompok.setBounds(10, 70, 100, 20);
getContentPane().add(cbkelompok);
cbkelompok.setBounds(75, 70, 100, 20);
setVisible(true);
}
public static void main(String args[]) {
combobox ap = new combobox();
ap.komponenVisual();
}
}
|
- · JCheckBox
import javax.swing.*;
import java.awt.*;
class chekbox extends JFrame {
JCheckBox cek1 = new JCheckBox("Pilihan 1");
JCheckBox cek2 = new JCheckBox("Pilihan 2");
JCheckBox cek3 = new JCheckBox("Pilihan 3");
chekbox() {
setLocation(200, 100);
setSize(300, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void KomponenVisual() {
getContentPane().add(cek1);
getContentPane().add(cek2);
getContentPane().add(cek3);
getContentPane().setLayout(new FlowLayout());
setVisible(true);
}
public static void main(String args[]) {
chekbox cb = new chekbox();
cb.KomponenVisual();
}
}
|
- · RadioButton
import javax.swing.*;
class radiobuton extends JFrame {
JLabel lblnim = new JLabel("NIM ");
JTextField txnim = new JTextField(20);
JButton tblcari = new JButton("Cari");
JLabel lblnama = new JLabel("Nama");
JTextField txnama = new JTextField(20);
JLabel lblkelas = new JLabel("Kelas ");
JRadioButton kelasA = new JRadioButton("A");
JRadioButton kelasB = new JRadioButton("B");
JRadioButton kelasC = new JRadioButton("C");
ButtonGroup grupkelas = new ButtonGroup();
radiobuton() {
setTitle("Lembar Penilaian");
setLocation(300, 100);
setSize(300, 150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void komponenVisual() {
getContentPane().setLayout(null);
getContentPane().add(lblnim);
lblnim.setBounds(10, 10, 70, 20);
getContentPane().add(txnim);
txnim.setBounds(75, 10, 100, 20);
getContentPane().add(tblcari);
tblcari.setBounds(180, 10, 95, 20);
getContentPane().add(lblnama);
lblnama.setBounds(10, 30, 70, 20);
getContentPane().add(txnama);
txnama.setBounds(75, 30, 200, 20);
getContentPane().add(lblkelas);
lblkelas.setBounds(10, 50, 100, 20);
getContentPane().add(kelasA);
kelasA.setBounds(75, 50, 50, 20);
getContentPane().add(kelasB);
kelasB.setBounds(125, 50, 50, 20);
getContentPane().add(kelasC);
kelasC.setBounds(175, 50, 50, 20);
grupkelas.add(kelasA);
grupkelas.add(kelasB);
grupkelas.add(kelasC);
setVisible(true);
}
public static void main(String args[]) {
radiobuton ap = new radiobuton();
ap.komponenVisual();
}
}
|
- · TextArea
import javax.swing.*;
import java.awt.*;
class textarea extends JFrame {
private JLabel label = new JLabel("Nama");
private JTextArea area1 = new JTextArea(3, 20);
textarea() {
setLocation(200, 100);
setSize(300, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().add(label);
getContentPane().add(area1);
getContentPane().setLayout(new FlowLayout());
}
public static void main(String args[]) {
textarea tf = new textarea();
}
}
|
- · JOptionPane
import javax.swing.JOptionPane;
public class optionpanee {
public static void main(String[] args) {
String st1 = "";
String st2 = "";
String st3 = "";
st1 = JOptionPane.showInputDialog("Nama");
st2 = JOptionPane.showInputDialog("NIM");
st3 = JOptionPane.showInputDialog("Kelas");
String msg = "Hello...Nama Saya " + st1 + "," + " NIM " + st2 + ","
+ " Saya dari kelas " + st3;
JOptionPane.showMessageDialog(null, msg);
}
}
|
- JList
import javax.swing.*;
import java.awt.*;
class List extends JFrame {
List(String title) {
setTitle(title);
setLocation(300, 100);
setSize(400, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel igna = new JPanel();
JPanel igna1 = new JPanel();
JPanel igna2 = new JPanel();
JButton B1 = new JButton("BACK");
JButton B2 = new JButton("NEXT");
JLabel lab = new JLabel("SILAKAN PILIH BUAH FAVORIT MU");
JList made = new JList(new String[] { "Apel", "Mangga", "Anggur","Alpokat","Jeruk","Pisang","Strawbery","Nanas",
"Nangka","Kedondong", "Pepaya" });
igna.setBackground(Color.gray);
igna.add(lab);
igna.add(made);
lab.setFont(new Font("Arial", Font.BOLD, 11));
made.setFont(new Font("Vijaya", Font.BOLD, 14));
lab.setForeground(Color.yellow);
made.setBackground(Color.green);
made.setForeground(Color.red);
igna.setLayout(new GridLayout(1, 1));
add(igna);
add(igna, BorderLayout.NORTH);
igna1.add(B1);
igna1.add(B2);
add(igna1);
igna1.setBackground(Color.black);
add(igna1, BorderLayout.SOUTH);
add(igna2);
igna2.setBackground(Color.pink);
add(igna2, BorderLayout.CENTER);
setVisible(true);
}
public static void main(String args[]) {
List IGNA = new List("Ignatius JList Program");
}
}
|
- · JButtonGroup
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JToggleButton;
import javax.swing.border.Border;
public class buttongroup {
public static void main(String args[]) {
JFrame frame = new JFrame("Button Group");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel(new GridLayout(0, 1));
Border border = BorderFactory.createTitledBorder("Examples");
panel.setBorder(border);
ButtonGroup group = new ButtonGroup();
AbstractButton abstract1 = new JToggleButton("Toggle Button");
panel.add(abstract1);
group.add(abstract1);
AbstractButton abstract2 = new JRadioButton("Radio Button");
panel.add(abstract2);
group.add(abstract2);
AbstractButton abstract3 = new JCheckBox("Check Box");
panel.add(abstract3);
group.add(abstract3);
AbstractButton abstract4 = new JRadioButtonMenuItem(
"Radio Button Menu Item");
panel.add(abstract4);
group.add(abstract4);
AbstractButton abstract5 = new JCheckBoxMenuItem("Check Box Menu Item");
panel.add(abstract5);
group.add(abstract5);
Container contentPane = frame.getContentPane();
contentPane.add(panel, BorderLayout.CENTER);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
|
Tidak ada komentar:
Posting Komentar