Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 077b370

Browse files
committed
Add initial Java Swing application setup with project files and basic UI components
1 parent ecdb375 commit 077b370

File tree

8 files changed

+146
-0
lines changed

8 files changed

+146
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.metadata/
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
4+
<attributes>
5+
<attribute name="module" value="true"/>
6+
</attributes>
7+
</classpathentry>
8+
<classpathentry kind="src" path="src"/>
9+
<classpathentry kind="output" path="bin"/>
10+
</classpath>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>TestJavaSwing</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
encoding/<project>=UTF-8
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=17
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
11+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
13+
org.eclipse.jdt.core.compiler.release=enabled
14+
org.eclipse.jdt.core.compiler.source=17
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package test;
2+
3+
import java.util.Vector;
4+
5+
import view.TestJavaSwing;
6+
7+
public class Test {
8+
public static void main(String[] args) {
9+
TestJavaSwing test = new TestJavaSwing();
10+
}
11+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package view;
2+
3+
import java.awt.EventQueue;
4+
5+
import javax.swing.JFrame;
6+
import javax.swing.JPanel;
7+
import javax.swing.border.EmptyBorder;
8+
import javax.swing.JButton;
9+
import javax.swing.JLabel;
10+
import java.awt.Color;
11+
import java.awt.Font;
12+
import java.awt.event.ActionListener;
13+
import java.util.Vector;
14+
import java.awt.event.ActionEvent;
15+
import javax.swing.JTextField;
16+
import javax.swing.JComboBox;
17+
18+
public class TestJavaSwing extends JFrame {
19+
20+
private JPanel contentPane;
21+
private JTextField textTf;
22+
private JButton addBt;
23+
private JLabel nameLb;
24+
private JTextField text2Tf;
25+
private JLabel nameLb_1;
26+
27+
public TestJavaSwing() {
28+
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
29+
setBounds(100, 100, 807, 536);
30+
contentPane = new JPanel();
31+
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
32+
33+
setContentPane(contentPane);
34+
contentPane.setLayout(null);
35+
36+
nameLb = new JLabel("Hải");
37+
nameLb.setFont(new Font("Tahoma", Font.PLAIN, 18));
38+
nameLb.setForeground(new Color(255, 0, 0));
39+
nameLb.setBackground(new Color(51, 255, 255));
40+
nameLb.setBounds(97, 113, 148, 41);
41+
nameLb.setText("Chào các bạn");
42+
contentPane.add(nameLb);
43+
44+
addBt = new JButton("Thêm");
45+
addBt.addActionListener(new ActionListener() {
46+
public void actionPerformed(ActionEvent e) {
47+
nameLb.setText( textTf.getText() );
48+
addBt.setText("Đã bấm");
49+
50+
String t = textTf.getText();
51+
int leng = t.length();
52+
text2Tf.setText(leng + "");
53+
}
54+
});
55+
addBt.setForeground(Color.RED);
56+
addBt.setBackground(new Color(0, 255, 255));
57+
addBt.setBounds(86, 194, 148, 49);
58+
contentPane.add(addBt);
59+
60+
textTf = new JTextField();
61+
textTf.setBackground(Color.LIGHT_GRAY);
62+
textTf.setBounds(296, 48, 243, 41);
63+
contentPane.add(textTf);
64+
textTf.setColumns(10);
65+
66+
text2Tf = new JTextField();
67+
text2Tf.setBounds(296, 116, 243, 41);
68+
contentPane.add(text2Tf);
69+
text2Tf.setColumns(10);
70+
71+
nameLb_1 = new JLabel("Chào các bạn");
72+
nameLb_1.setForeground(Color.RED);
73+
nameLb_1.setFont(new Font("Tahoma", Font.PLAIN, 18));
74+
nameLb_1.setBackground(new Color(51, 255, 255));
75+
nameLb_1.setBounds(97, 48, 148, 41);
76+
contentPane.add(nameLb_1);
77+
78+
79+
Vector v = new Vector();
80+
v.add("Cam");
81+
v.add("Bưởi");
82+
v.add("Nho");
83+
JComboBox comboBox = new JComboBox(v);
84+
comboBox.setBounds(387, 198, 141, 41);
85+
contentPane.add(comboBox);
86+
87+
setVisible(true);
88+
setTitle("Ứng dụng quản lý");
89+
}
90+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /