0% found this document useful (0 votes)
29 views

SetBound ActionListener

The document describes Java code for a student information application. It creates two classes - one called zeref that contains labels, text fields and buttons to input student name and class. It then passes this data to a second class called sambung that displays the information. The code shows how to transfer data between classes in Java.

Uploaded by

Izudin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

SetBound ActionListener

The document describes Java code for a student information application. It creates two classes - one called zeref that contains labels, text fields and buttons to input student name and class. It then passes this data to a second class called sambung that displays the information. The code shows how to transfer data between classes in Java.

Uploaded by

Izudin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Coding setBound

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class zeref extends JFrame implements ActionListener {
JPanel p1;
JTextField tf1,tf2;
JButton b1;
JLabel ltitle,l1,l2;
public zeref(){
setLayout(null);
p1 = new JPanel(null);
p1.setBounds(0, 0, 400, 500);
p1.setBackground(Color.yellow);
ltitle = new JLabel("Student Information ");
ltitle.setBounds(70, 40, 150,50);
l1 = new JLabel(" Nama: ");
l1.setBounds(5, 80, 150, 20);
tf1 = new JTextField(20);
tf1.setBounds(6, 100, 150, 20);
l2 = new JLabel(" Kelas");
l2.setBounds(7, 120, 150, 20);
tf2 = new JTextField(20);
tf2.setBounds(8, 140, 150, 20);
b1 = new JButton("Tekan Saya");
b1.setBounds(9, 170, 100, 30);
b1.addActionListener(this);
add(p1);
p1.add(ltitle);
p1.add(l1);
p1.add(tf1);
p1.add(l2);
p1.add(tf2);
p1.add(b1);
}
public void actionPerformed(ActionEvent e){
String nama = tf1.getText();
String kelas = tf2.getText();

if(e.getSource() == b1){
sambung s = new sambung(nama,kelas);
s.setVisible(true);
setVisible(false);
}
}

public static void main(String[] args) {


zeref z = new zeref();
z.setVisible(true);
z.setTitle("Exercise Aku");
z.setSize(300,400);
z.setDefaultCloseOperation(EXIT_ON_CLOSE);
z.setLocationRelativeTo(null);
}
}

Create class baru utk smbgn coding setBound di atas ^|^ (continue)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class sambung extends JFrame implements ActionListener {
JLabel lnama,lkelas,ltajuk;
JButton btexit;
public sambung(String n, String k){
setSize(300,300);
setVisible(true);
setLayout(null);
setTitle("Send Data");
ltajuk = new JLabel("Student Information");
ltajuk.setBounds(70, 40, 150,50);
lnama = new JLabel(" Nama: "+n);
lnama.setBounds(5, 80, 150, 20);
lkelas = new JLabel(" Kelas: "+k);
lkelas.setBounds(5, 105, 150, 20);
btexit = new JButton("Exit");
btexit.setBounds(9, 130, 100, 30);
btexit.addActionListener((ActionListener) this);
add(ltajuk);
add(lnama);
add(lkelas);
add(btexit);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==btexit){
System.exit(0);
}
}

#kelastambahanjava #15/1/2016 #8.50pm

You might also like