You are on page 1of 3

Materi UAS

Kelas/Pewarisan Class

Polimorfisme

Interface

Inner Class

Pengenalan GUI

5 soal , waktu 75 menit, buku terbuka

1. Lengkapilah program berikut agar sesuai tampilan:

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

public class TesFrame3 extends Frame {


public static void main(String[] args) {
TesFrame3 apl = new TesFrame3();
}

public TesFrame3() {
super(“Tes Frame” );
setSize(300, 100);

addWindowListener(
new TesFrame3. apl.. ;

show();
}

class TesFrame3 extends WindowAdapter {


public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
}
2. Lengaka

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class DemoJButtonInterface extends JFrame


implements ActionListener {

private JButton btn;

public DemoJButtonInterface()
{
super(Frame);

Container c = getContentPane();
c.setLayout( new FlowLayout() );

btn = new JButton("Button");


Frame.add(btn);

btn.addActionListener(this);

setSize( 275, 100 );


show();
}

public static void main( String args[] )


{
DemoJButtonInterface app = new DemoJButtonInterface();

apr .addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent event)
{
System.exit( 0 );
}
}
);
}

public void actionPerformed(ActionEvent event)


{
JOptionPane.showMessageDialog( null,
"Anda telah menekan : " + btn.getActionCommand() + "\n" +
"Handler Button ini menggunakan prinsip interface");
}

You might also like