Skip to content

Commit 94405e2

Browse files
authored
Graphics .java project
1 parent 5c882e5 commit 94405e2

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

MyUserInteraction.java

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import java.awt.EventQueue;
2+
3+
import javax.swing.JFrame;
4+
import javax.swing.JLabel;
5+
import javax.swing.SwingConstants;
6+
import javax.swing.JTextField;
7+
import javax.swing.JButton;
8+
import java.awt.event.ActionListener;
9+
import java.awt.event.ActionEvent;
10+
import java.awt.Color;
11+
import java.awt.Font;
12+
13+
public class MyUserInteraction {
14+
15+
private JFrame frame;
16+
private JLabel myLabel;
17+
private JTextField textField;
18+
private JButton myButton;
19+
/**
20+
* Launch the application.
21+
*/
22+
public static void main(String[] args) {
23+
EventQueue.invokeLater(new Runnable() {
24+
public void run() {
25+
try {
26+
MyUserInteraction window = new MyUserInteraction();
27+
window.frame.setVisible(true);
28+
} catch (Exception e) {
29+
e.printStackTrace();
30+
}
31+
}
32+
});
33+
}
34+
35+
/**
36+
* Create the application.
37+
*/
38+
public MyUserInteraction() {
39+
initialize();
40+
}
41+
42+
/**
43+
* Initialize the contents of the frame.
44+
*/
45+
private void initialize() {
46+
frame = new JFrame();
47+
frame.getContentPane().setFont(new Font("Kohinoor Telugu", Font.PLAIN, 13));
48+
frame.getContentPane().setBackground(Color.YELLOW);
49+
frame.setBackground(Color.GRAY);
50+
frame.setBounds(100, 100, 863, 377);
51+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
52+
frame.getContentPane().setLayout(null);
53+
54+
JLabel MyLabel = new JLabel("Change Me");
55+
MyLabel.setFont(new Font("Lucida Grande", Font.PLAIN, 27));
56+
MyLabel.setBackground(Color.YELLOW);
57+
MyLabel.setHorizontalAlignment(SwingConstants.CENTER);
58+
MyLabel.setBounds(398, 59, 212, 37);
59+
frame.getContentPane().add(MyLabel);
60+
61+
textField = new JTextField();
62+
textField.setBackground(Color.MAGENTA);
63+
textField.setHorizontalAlignment(SwingConstants.CENTER);
64+
textField.setBounds(425, 132, 130, 26);
65+
frame.getContentPane().add(textField);
66+
textField.setColumns(10);
67+
68+
JButton mybutton = new JButton("click me");
69+
mybutton.setBackground(Color.CYAN);
70+
mybutton.addActionListener(new ActionListener() {
71+
public void actionPerformed(ActionEvent e) {
72+
String text = textField.getText();
73+
myLabel.setText(text);
74+
textField.setText("");
75+
}
76+
77+
});
78+
mybutton.setBounds(405, 180, 117, 29);
79+
frame.getContentPane().add(mybutton);
80+
}
81+
}

0 commit comments

Comments
 (0)