Portfolio

JButton


import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;


public class dop extends JFrame {

private JButton as;
private JButton qw;

public dop() {
super("title");
setLayout( new FlowLayout());

as = new JButton("Buto");
add(as);

qw = new JButton("po");
add(qw);

Han hano = new Han();
as.addActionListener(hano);
qw.addActionListener(hano);
}

private class Han implements ActionListener{

public void actionPerformed(ActionEvent event) {
JOptionPane.showMessageDialog(null, String.format("%s", event.getActionCommand()));
}
}
}

 

import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.Icon;
import javax.swing.JOptionPane;


public class Gui extends JFrame{

private JButton reg;
private JButton custom;

public Gui() {
super("the title");
setLayout(new FlowLayout());

reg = new JButton("button");
add(reg);

Icon b = new ImageIcon(getClass().getResource("b.png"));
Icon x = new ImageIcon(getClass().getResource("x.png"));
custom = new JButton("Custom", b);
custom.setRolloverIcon(x);
add(custom);



HandlerClass handler = new HandlerClass();
reg.addActionListener(handler);
custom.addActionListener(handler);

dop doop= new dop();
doop.setDefaultCloseOperation(EXIT_ON_CLOSE);
doop.setSize(640, 480);
doop.setVisible(true);

}

private class HandlerClass implements ActionListener {

public void actionPerformed(ActionEvent event) {
JOptionPane.showMessageDialog(null,String.format("%s", event.getActionCommand()));
}
}

}

 

import javax.swing.JFrame;

public class apple {

public static void main(String[] args) {

Gui go = new Gui();
go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
go.setSize(600,480);
go.setVisible(true);

}

}