Shanswing

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

SHAN FRANCIS VILLANUEVA public static void main(String[] args) {

BSIT 2A-G2 SwingUtilities.invokeLater(() -> {


new JFrameDemo().setVisible(true);
package jframedemo; });
}
import java.awt.*;
import java.awt.event.*; @Override
import javax.swing.*; public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnCancel) {
public class JFrameDemo extends JFrame System.exit(0);
implements ActionListener { } else if (e.getSource() == btnOk) {
JButton btnOk = new JButton("OK"); System.out.println("OK");
JButton btnCancel = new JButton("CANCEL"); }
FlowLayout flow = new FlowLayout(); }

JPanel lbl = new JPanel(); }


JPanel lbl2 = new JPanel();

JFrameDemo() {
setLayout(flow);
add(btnOk);
add(btnCancel);

btnCancel.addActionListener(this);
btnOk.addActionListener(this);

setSize(500, 300);
setLocationRelativeTo(null);
setTitle("Shan Francis Villanueva");

setDefaultCloseOperation(JFrame.EXIT_ON_CLO
SE);

add(lbl);
lbl.setBackground(Color.RED);
lbl.setPreferredSize(new Dimension(400,
150));

add(lbl2);
lbl2.setBackground(Color.BLUE);
lbl2.setPreferredSize(new Dimension(400,
150));
}

You might also like