Senin, 21 Mei 2012

textArea

Input:


import javax.swing.*;
public class textArea{
public static void main (String[]args){
JFrame f=new JFrame();
JTextArea area=new JTextArea();
f.setSize(250,200);
area.setBounds(50,50,150,100);
f.add(area);
f.setLayout(null);
f.setVisible(true);
}
}

Output:























Combo Dan checkBox

Input: Combo

import javax.swing.*;
class combo{
public static void main( String[] args){
String [] pilihan={"pilihan 1","pilihan 2 "," pilihan 3 "," pilihan 4 "};
JComboBox cb=new JComboBox(pilihan);
JFrame frame= new JFrame ();
frame.setSize(180,200);
cb.setBounds(10,10,150,25);
frame.add(cb);
frame.setLayout(null);
frame.setVisible( true);
}
}

Output : 















Input : checkBox

import javax.swing.*;
class checkBox{
public static void main (String[]args){
JCheckBox c1=new JCheckBox("pilihan 1");
JFrame frame=new JFrame();
frame.setSize(200,200);
c1.setBounds(50,50,150,25);
frame.add(c1);
frame.setLayout(null);
frame.setVisible(true);
}
}

Output:








RadioButton

Input:



import javax.swing.*;
class radioButton{
public static void main (String[]args){

JRadioButton r1=new JRadioButton ("pilih 1");
JRadioButton r2=new JRadioButton ("pilih 2");

ButtonGroup g=new ButtonGroup();

JFrame frame =new JFrame();
frame.setSize(150,150);
r1.setBounds(30,50,150,25);
r2.setBounds(30,70,150,25);

frame.add(r1);
frame.add(r2);

g.add(r1);
g.add(r2);

frame.setLayout(null);
frame.setVisible(true);
}
}


Output:












Agar otomatis menyentang 1 pilihan saja, gunakan

ButtonGroup g=new ButtonGroup();
g.add(r1);
g.add(rd)



Jumat, 18 Mei 2012

Membuat Label

Input:

import javax.swing.JLabel;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.*;

class Label
{public static void main (String[]args)
{JLabel lbl=new JLabel("MASUKAN DATA ANDA :");
JLabel lbl1=new JLabel("Nama Anda :");
JLabel lbl2=new JLabel("NPM Anda :");
JLabel lbl3=new JLabel("Jurusan Anda :");
JLabel lbl4=new JLabel("Alamat Anda :");

JFrame frame=new JFrame();

JTextField txt1=new JTextField();
JTextField txt2=new JTextField();
JTextField txt3=new JTextField();
JTextField txt4=new JTextField();
JButton bttn= new JButton("Done");

lbl.setBounds(160,50,150,25);
lbl1.setBounds(100,120,90,25);
txt1.setBounds (190,120,150,25);
bttn.setBounds(190,250,80,25);

lbl2.setBounds(100,140,100,25);
txt2.setBounds (190,140,150,25);

lbl3.setBounds(100,160,110,25);
txt3.setBounds (190,160,150,25);

lbl4.setBounds(100,180,120,25);
txt4.setBounds (190,180,150,50);

frame.add(lbl);
frame.add(lbl1);
frame.add(txt1);
frame.add(txt2);
frame.add(txt3);
frame.add(txt4);
frame.add(bttn);

frame.add(lbl2);
frame.add(txt2);
frame.add(lbl3);
frame.add(lbl4);

frame.setSize(500,500);
frame.setLayout(null);
frame.setVisible(true);
}
}



Output:


Membuat Button

Input :
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.*;
  public class buton
{
public static void main (String[]xXx)
{
JFrame frame= new JFrame();
JButton bttn=new JButton ("Oke");
frame.setSize(200,150);
bttn.setBounds(10,40,150,25);
frame.add(bttn);
frame.setLayout(null);
frame.setVisible(true);
}
}


Output:


Membuat TextField

Input:

import javax.swing.JTextField;
import javax.swing.JFrame;
class Textt
{ public static void main(String[]args)
{JTextField txt=new JTextField();
JFrame frame=new JFrame();
frame.setSize(500,300);
frame.add(txt);
txt.setBounds(50,10,150,25);
frame.setLayout(null);
frame.setVisible(true);
}
}

Output:



Membuat Frame Visual Java

Input:

import javax.swing.JFrame;
public class frame1
{ public static void main(String[]xXx)
{JFrame frame=new JFrame();
frame.setTitle("program visual");
frame.setVisible(true);
}
}


Output:







Input:

import javax.swing.JFrame;
public class frame2
{public static void main (String[]xXx)
{JFrame frame= new JFrame();
frame.setSize(300,300);
frame.setVisible(true);
}
}


Output: