Created
August 19, 2023 07:59
-
-
Save mt3o/056b22e78a158ee32a25fefdeca4c7b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.JFrame; | |
import javax.swing.JButton; | |
import javax.swing.JTextField; | |
import javax.swing.JLabel; | |
public class d { | |
public static void main(String[] args) { | |
int x = 650; | |
int y = 200; | |
int w = 120; | |
int h = 35; | |
int x1 = 650; | |
int y1 = 100; | |
int w1 = 180; | |
int h1 = h; | |
JFrame f = new JFrame("New Project"); | |
JButton b = new JButton("Calculate "); | |
JTextField tf = new JTextField(); | |
JLabel l = new JLabel("Enter the no. to find its table = "); | |
JLabel l1 = new JLabel(); | |
l.setBounds(x1 - 200, y1, w1, h1); | |
tf.setBounds(x1, y1, w1, h1); | |
b.setBounds(x, y, w, h); | |
l1.setBounds(x - 100, y + 100, w1, h1); | |
b.addActionListener(e -> { | |
int n = Integer.parseInt(tf.getText()); | |
String s1="", s2=""; | |
String s = "The table of " + n + " is = "; | |
for (int i = 1; i <= 10; i++) { | |
int a = i * n; | |
s1 += "%d x %d = %d \n".formatted(n, i, a); | |
} | |
s2 = s + s1 ; | |
l1.setText(s2); | |
}); | |
f.add(b); | |
f.add(tf); | |
f.add(l); | |
f.add(l1); | |
f.setSize(900, 900); | |
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
f.setLayout(null); | |
f.setVisible(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment