import javax.swing.*;
class Labels extends JFrame{ JPanel pnl = new JPanel();
ImageIcon duke = new ImageIcon("duke.png");
JLabel lbl1 = new JLabel(duke);
JLabel lbl2 = new JLabel("Duke is the friendly mascot of Java technology.");
JLabel lbl3 = new JLabel ("Duke", duke, JLabel.CENTER);
public Labels(){
super("Swing Labels");
setSize(1000 , 800);
setDefaultCloseOperation( EXIT_ON_CLOSE);
add(pnl);
setVisible(true);
lbl1.setToolTipText("Duke - the Java Mascot");
lbl3.setHorizontalTextPosition(JLabel.CENTER);
lbl3.setVerticalTextPosition(JLabel.BOTTOM);
pnl.add(lbl1);
pnl.add(lbl2);
pnl.add(lbl3);
}
public static void main(String [] args){
Labels gui = new Labels();
}
}
What if I want to use this as a JApplet? what has to be done? Is it hard to change?
The things that run on a JFrame are the same as the ones on a JApplet?
As I recommended in one of your previous questions, you should re-organize your program to conform to the Model-View-Controller pattern, or one of its variants, as this will allow you to cleanly separate out the control code (that called by the ActionListener) from the GUI. For an example of an M-V-C program, please check out my suggestions and code in this recent answer.
Well okay first check this out: action listener in another class - java
now all you have to do is edit it to your needs, and in the actionPerformed(ActionEvent ae)
you will then get the values in controlB.java class by accessing the data using a accessor/get method or make the Actionlistener class extend the ControlB so it will have access to all its public data, then once you have the values, pass them to the Graph.java either during initiation or using a mutator/set method?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With