JAVA MAIN FILE
-----------------
package jbutton;
import javax.swing.JFrame;
public class Main
{
public static void main(String[] args)
{
button obj = new button();
obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
obj.setSize(400, 400);
obj.setVisible(true);
}
}
JAVA CLASS FILE
-------------------
package jbutton;
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.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
public class button extends JFrame
{
private JButton reg;
private JButton custom;
public button()
{
super("the title");
setLayout(new FlowLayout());
reg = new JButton("reg button");
add(reg);
//Icon b = new ImageIcon(getClass.getResource("a.png"));
//Icon x = new ImageIcon(getClass.getResource("b.png"));
//custom = new JButton("Custom", b);
custom = new JButton("Custom");
//custom.setRolloverIcon(x);
add(custom);
HandlerClass handler = new HandlerClass();
reg.addActionListener(handler);
custom.addActionListener(handler);
}
private class HandlerClass implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
JOptionPane.showMessageDialog(null, String.format("%s", ae.getActionCommand()), "Is my title title", JOptionPane.PLAIN_MESSAGE);
}
}
}
-----------------
package jbutton;
import javax.swing.JFrame;
public class Main
{
public static void main(String[] args)
{
button obj = new button();
obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
obj.setSize(400, 400);
obj.setVisible(true);
}
}
JAVA CLASS FILE
-------------------
package jbutton;
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.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
public class button extends JFrame
{
private JButton reg;
private JButton custom;
public button()
{
super("the title");
setLayout(new FlowLayout());
reg = new JButton("reg button");
add(reg);
//Icon b = new ImageIcon(getClass.getResource("a.png"));
//Icon x = new ImageIcon(getClass.getResource("b.png"));
//custom = new JButton("Custom", b);
custom = new JButton("Custom");
//custom.setRolloverIcon(x);
add(custom);
HandlerClass handler = new HandlerClass();
reg.addActionListener(handler);
custom.addActionListener(handler);
}
private class HandlerClass implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
JOptionPane.showMessageDialog(null, String.format("%s", ae.getActionCommand()), "Is my title title", JOptionPane.PLAIN_MESSAGE);
}
}
}
No comments:
Post a Comment