Skip to content

Commit

Permalink
java program-12-added
Browse files Browse the repository at this point in the history
  • Loading branch information
rajjitlai committed Dec 19, 2024
1 parent d7dc409 commit ddcf4e7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Binary file added Java/programs/question12/InfoApplet.class
Binary file not shown.
41 changes: 41 additions & 0 deletions Java/programs/question12/InfoApplet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

@SuppressWarnings("removal")
public class InfoApplet extends Applet implements ActionListener{
Button buttonA, buttonB;
String message = "";

@Override
public void init() {
setLayout(new FlowLayout());
setBackground(Color.LIGHT_GRAY);

buttonA = new Button("A");
buttonB = new Button("B");

add(buttonA);
add(buttonB);

buttonA.addActionListener(this);
buttonB.addActionListener(this);
}

@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == buttonA){
message = "You clicked button A";
} else if(e.getSource() == buttonB){
message = "You clicked button B";
}
repaint();
}

@Override
public void paint(Graphics g) {
g.setFont(new Font("Arial", Font.BOLD, 14));
g.setColor(Color.BLACK);
g.drawString(message, 20, 100);
}
}

0 comments on commit ddcf4e7

Please sign in to comment.