1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
|
import java.awt.EventQueue;
public class HOCHtiefGUI implements ActionListener {
private JFrame frame;
private JTextField textField;
private static int versuche = 0;
private JProgressBar progressBar;
/*
* int comp = computerZahl(); private static String input = ""; static
* HOCHtiefGUI window; JButton los; int[] inputs = { 1 };
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
HOCHtiefGUI window;
window = new HOCHtiefGUI();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*
* @wbp.parser.entryPoint
*/
public HOCHtiefGUI() {
int comp = computerZahl();
String input = "";
JButton los;
int[] inputs = { 1 };
initialize(meldung(versuche, input, tester(input, comp), comp),
versuche(inputs), versuche);
}
public String versuche(int[] inputs) {
int i = 0;
String out = "";
while (i < 5) {
if ((inputs.length + i) - 5 < 0) {
out = out + "- \n\n";
} else {
out = out + String.valueOf(inputs[4 - i]);
out = out + " ";
}
i++;
}
return out;
}
public String meldung(int versuche, String input, boolean finish, int zahl) {
if (versuche < 5 && finish) {
return "Herzlichen Glueckwunsch, Sie haben die Zahl gefunden!";
}
if (versuche == 5) {
return ("Leider verloren! Die gesuchte Zahl war " + zahl);
}
if (input.length() == 0) {
return "Viel Glueck!";
}
if (Integer.parseInt(input) < zahl) {
return "Die gesuchte Zahl ist groesser!";
}
if (Integer.parseInt(input) > zahl) {
return "Die gesuchte Zahl ist kleiner!";
}
return "Da stimmt was nicht!";
}
public boolean tester(String input, int zahl) {
if (input.length() == 0) {
return false;
}
if (Integer.parseInt(input) == zahl) {
return true;
} else {
return false;
}
}
public int computerZahl() {
long compzahl = System.currentTimeMillis();
String zahl = String.valueOf(compzahl);
zahl = zahl.substring(zahl.length() - 2);
int zahlout = Integer.parseInt(zahl);
return zahlout;
}
public void actionPerformed(ActionEvent e) {
versuche++;
}
/**
* Initialize the contents of the frame.
*
* @wbp.parser.entryPoint
*/
public void initialize(String meldung, String versuche, int balken) {
frame = new JFrame();
frame.getContentPane().setBackground(new Color(205, 133, 63));
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JTextPane txtpnFindeDieGesuchte = new JTextPane();
txtpnFindeDieGesuchte.setBounds(0, 0, 450, 50);
txtpnFindeDieGesuchte.setBackground(Color.GRAY);
txtpnFindeDieGesuchte.setEditable(false);
txtpnFindeDieGesuchte
.setToolTipText("Der Computer w\u00E4hlt eine Zahl zwischen "
+ "0 und 99. Du hast f\u00FCnf Versuche, "
+ "diese zu erraten.");
txtpnFindeDieGesuchte
.setText("\n Finde die gesuchte Zahl! "
+ "(Zahl zwischen 0 und 99)\n");
frame.getContentPane().add(txtpnFindeDieGesuchte);
JTextPane txtpnVersuche = new JTextPane();
txtpnVersuche.setBounds(355, 53, 167, 50);
txtpnVersuche.setBackground(new Color(205, 133, 63));
txtpnVersuche.setEditable(false);
txtpnVersuche.setText("\n\n Versuche:");
frame.getContentPane().add(txtpnVersuche);
JProgressBar progressBar = new JProgressBar();
progressBar.setValue(this.versuche);
progressBar.setForeground(new Color(205, 133, 63));
progressBar.setFont(new Font("Impact", Font.PLAIN, 13));
progressBar.setMaximum(5);
progressBar.setOrientation(SwingConstants.VERTICAL);
progressBar.setBounds(365, 126, 30, 146);
frame.getContentPane().add(progressBar);
JTextArea txtrGibHierDeine = new JTextArea();
txtrGibHierDeine.setFont(txtrGibHierDeine.getFont().deriveFont(
txtrGibHierDeine.getFont().getSize() + 5f));
txtrGibHierDeine.setBackground(new Color(205, 133, 63));
txtrGibHierDeine.setEditable(false);
txtrGibHierDeine.setText("Gib hier deine Zahl ein:");
txtrGibHierDeine.setBounds(38, 78, 231, 23);
frame.getContentPane().add(txtrGibHierDeine);
textField = new JTextField();
textField.setBounds(72, 124, 134, 28);
frame.getContentPane().add(textField);
textField.setColumns(2);
JButton los = new JButton("los");
los.setBounds(226, 125, 117, 29);
los.addActionListener(this);
los.setEnabled(true);
frame.getContentPane().add(los);
JTextPane txtpnH = new JTextPane();
txtpnH.setText(versuche);
txtpnH.setEditable(false);
txtpnH.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
txtpnH.setBackground(Color.GRAY);
txtpnH.setBounds(407, 126, 17, 146);
frame.getContentPane().add(txtpnH);
JTextPane txtpnNichtGanzDie = new JTextPane();
txtpnNichtGanzDie.setBackground(new Color(128, 128, 128));
txtpnNichtGanzDie.setText("\n\n" + meldung);
txtpnNichtGanzDie.setEditable(false);
txtpnNichtGanzDie.setFont(new Font("Lucida Grande", Font.PLAIN, 15));
txtpnNichtGanzDie.setBounds(38, 164, 298, 108);
frame.getContentPane().add(txtpnNichtGanzDie);
}
}
|