質問編集履歴

4

質問内容の改善

2018/11/05 21:31

投稿

uyu
uyu

スコア12

test CHANGED
File without changes
test CHANGED
@@ -8,11 +8,11 @@
8
8
 
9
9
  パスワードを認証してOKを押したら家計簿の表が表示されるのが理想です。
10
10
 
11
- どなかわかる人いらっしゃいましたら教えてください。
11
+ コードを書いてみのです
12
+
13
+ "actionPerformed(ActionEvent)はすでにクラスKakeibo3で定義されています"と出てしまいます。
12
14
 
13
15
  ちなみにプログラミングにはjava8、ATOMを使用しています。
14
-
15
- 足りない情報があれば随時追加させていただきます。
16
16
 
17
17
  よろしくお願いいたします。
18
18
 
@@ -20,9 +20,9 @@
20
20
 
21
21
 
22
22
 
23
- パスワード認証↓
23
+ import javax.swing.*;
24
24
 
25
- import javax.swing.*;
25
+ import javax.swing.table.*;
26
26
 
27
27
  import java.awt.*;
28
28
 
@@ -30,101 +30,87 @@
30
30
 
31
31
 
32
32
 
33
- class Kakeibo extends JFrame implements ActionListener{
33
+ class Kakeibo3 extends JFrame implements ActionListener{
34
34
 
35
35
  JPasswordField pass;
36
36
 
37
37
 
38
38
 
39
- public static void main(String args[]){
39
+ public static void main(String[] args){
40
40
 
41
- Kakeibo frame = new Kakeibo("家計簿");
41
+ Kakeibo3 frame = new Kakeibo3("家計簿");
42
42
 
43
- frame.setVisible(true);
43
+ frame.setVisible(true);
44
44
 
45
- }
45
+ }
46
+
47
+ Kakeibo3(String title){
48
+
49
+ setTitle(title);
50
+
51
+ setBounds(100,100,500,500);
52
+
53
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
46
54
 
47
55
 
48
56
 
49
- Kakeibo(String title){
57
+ JPanel p = new JPanel();
50
-
51
- setTitle(title);
52
-
53
- setBounds(100,100,500,500);
54
-
55
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
56
58
 
57
59
 
58
60
 
61
+ JLabel label = new JLabel("パスワード");
62
+
59
- JPanel p = new JPanel();
63
+ pass = new JPasswordField(10);
60
64
 
61
65
 
62
66
 
63
- JLabel label = new JLabel("パスワード");
67
+ JButton button = new JButton("確認");
64
68
 
65
- pass = new JPasswordField(10);
69
+ button.addActionListener(this);
66
70
 
67
71
 
68
72
 
69
- JButton button = new JButton("確認");
73
+ p.add(label);
70
74
 
75
+ p.add(pass);
76
+
71
- button.addActionListener(this);
77
+ p.add(button);
72
78
 
73
79
 
74
80
 
75
- p.add(label);
81
+ Container contentPane = getContentPane();
76
82
 
77
- p.add(pass);
83
+ contentPane.add(p,BorderLayout.CENTER);
78
84
 
79
- p.add(button);
85
+ }
80
86
 
81
87
 
82
88
 
83
- Container contentPane = getContentPane();
89
+ public void actionPerformed(ActionEvent e){
84
90
 
85
- contentPane.add(p,BorderLayout.CENTER);
91
+ String password = new String(pass.getPassword());
86
-
87
- }
88
92
 
89
93
 
90
94
 
91
- public void actionPerformed(ActionEvent e){
95
+ if(password.equals("tan01200709")){
92
96
 
93
- String password = new String(pass.getPassword());
97
+ JLabel label = new JLabel("認証に成功しました");
94
98
 
99
+ JOptionPane.showMessageDialog(this,label,"成功",JOptionPane.INFORMATION_MESSAGE);
95
100
 
101
+ }else{
96
102
 
97
- if(password.equals("0000")){
103
+ JLabel label = new JLabel("パスワードが違います");
98
104
 
99
- JLabel label = new JLabel("認証に成功しました");
105
+ JOptionPane.showMessageDialog(this,label,"失敗",JOptionPane.ERROR_MESSAGE);
100
106
 
101
- JOptionPane.showMessageDialog(this,label,"成功",JOptionPane.INFORMATION_MESSAGE);
102
-
103
- }else{
104
-
105
- JLabel label = new JLabel("パスワードが違います");
106
-
107
- JOptionPane.showMessageDialog(this,label,"失敗",JOptionPane.ERROR_MESSAGE);
108
-
109
- pass.setText("");
107
+ pass.setText("");
110
108
 
111
109
  }
112
110
 
113
111
  }
114
112
 
115
- }
116
113
 
117
-
118
-
119
- 表コード↓
120
-
121
- import javax.swing.*;
122
-
123
- import javax.swing.table.*;
124
-
125
-
126
-
127
- public class Kakeibo2{
128
114
 
129
115
  private JTable table;
130
116
 
@@ -134,11 +120,13 @@
134
120
 
135
121
 
136
122
 
137
- public Kakeibo2(){
123
+ public void actionPerformed(ActionEvent e){
138
124
 
139
125
  String[] header = {"収入","支出","残高"};
140
126
 
141
127
  model = new DefaultTableModel(header,10);
128
+
129
+
142
130
 
143
131
  table = new JTable(model);
144
132
 
@@ -146,24 +134,4 @@
146
134
 
147
135
  }
148
136
 
149
-
150
-
151
- public static void main(String[] args){
152
-
153
- Kakeibo2 sample = new Kakeibo2();
154
-
155
-
156
-
157
- JFrame frame = new JFrame("家計簿");
158
-
159
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
160
-
161
- frame.getContentPane().add(sample.sp, "Center");
162
-
163
- frame.pack();
164
-
165
- frame.setVisible(true);
166
-
167
- }
168
-
169
137
  }

3

説明の追加

2018/11/05 21:30

投稿

uyu
uyu

スコア12

test CHANGED
File without changes
test CHANGED
@@ -11,6 +11,8 @@
11
11
  どなたかわかる人がいらっしゃいましたら教えてください。
12
12
 
13
13
  ちなみにプログラミングにはjava8、ATOMを使用しています。
14
+
15
+ 足りない情報があれば随時追加させていただきます。
14
16
 
15
17
  よろしくお願いいたします。
16
18
 

2

質問内容の改善

2018/11/05 14:04

投稿

uyu
uyu

スコア12

test CHANGED
File without changes
test CHANGED
@@ -2,16 +2,166 @@
2
2
 
3
3
  できれば家計簿を作りたいと思っています。
4
4
 
5
+ パスワード認証画面を作るのと表を作るプログラムはそれぞれ書けたのですが、
5
6
 
6
-
7
- パスワード認証画面を作るのと表を作る手順はそれぞれわかったのですが、
8
-
9
- これらを関係させる手順がわかりません。
7
+ これらをどう関係させればよいのかがわかりません。
10
8
 
11
9
  パスワードを認証してOKを押したら家計簿の表が表示されるのが理想です。
12
10
 
13
11
  どなたかわかる人がいらっしゃいましたら教えてください。
14
12
 
15
- ちなみにプログラミングにはATOMを使用しています。
13
+ ちなみにプログラミングにはjava8、ATOMを使用しています。
16
14
 
17
15
  よろしくお願いいたします。
16
+
17
+ 以下コードです。
18
+
19
+
20
+
21
+ パスワード認証↓
22
+
23
+ import javax.swing.*;
24
+
25
+ import java.awt.*;
26
+
27
+ import java.awt.event.*;
28
+
29
+
30
+
31
+ class Kakeibo extends JFrame implements ActionListener{
32
+
33
+ JPasswordField pass;
34
+
35
+
36
+
37
+ public static void main(String args[]){
38
+
39
+ Kakeibo frame = new Kakeibo("家計簿");
40
+
41
+ frame.setVisible(true);
42
+
43
+ }
44
+
45
+
46
+
47
+ Kakeibo(String title){
48
+
49
+ setTitle(title);
50
+
51
+ setBounds(100,100,500,500);
52
+
53
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
54
+
55
+
56
+
57
+ JPanel p = new JPanel();
58
+
59
+
60
+
61
+ JLabel label = new JLabel("パスワード");
62
+
63
+ pass = new JPasswordField(10);
64
+
65
+
66
+
67
+ JButton button = new JButton("確認");
68
+
69
+ button.addActionListener(this);
70
+
71
+
72
+
73
+ p.add(label);
74
+
75
+ p.add(pass);
76
+
77
+ p.add(button);
78
+
79
+
80
+
81
+ Container contentPane = getContentPane();
82
+
83
+ contentPane.add(p,BorderLayout.CENTER);
84
+
85
+ }
86
+
87
+
88
+
89
+ public void actionPerformed(ActionEvent e){
90
+
91
+ String password = new String(pass.getPassword());
92
+
93
+
94
+
95
+ if(password.equals("0000")){
96
+
97
+ JLabel label = new JLabel("認証に成功しました");
98
+
99
+ JOptionPane.showMessageDialog(this,label,"成功",JOptionPane.INFORMATION_MESSAGE);
100
+
101
+ }else{
102
+
103
+ JLabel label = new JLabel("パスワードが違います");
104
+
105
+ JOptionPane.showMessageDialog(this,label,"失敗",JOptionPane.ERROR_MESSAGE);
106
+
107
+ pass.setText("");
108
+
109
+ }
110
+
111
+ }
112
+
113
+ }
114
+
115
+
116
+
117
+ 表コード↓
118
+
119
+ import javax.swing.*;
120
+
121
+ import javax.swing.table.*;
122
+
123
+
124
+
125
+ public class Kakeibo2{
126
+
127
+ private JTable table;
128
+
129
+ private JScrollPane sp;
130
+
131
+ private DefaultTableModel model;
132
+
133
+
134
+
135
+ public Kakeibo2(){
136
+
137
+ String[] header = {"収入","支出","残高"};
138
+
139
+ model = new DefaultTableModel(header,10);
140
+
141
+ table = new JTable(model);
142
+
143
+ sp = new JScrollPane(table);
144
+
145
+ }
146
+
147
+
148
+
149
+ public static void main(String[] args){
150
+
151
+ Kakeibo2 sample = new Kakeibo2();
152
+
153
+
154
+
155
+ JFrame frame = new JFrame("家計簿");
156
+
157
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
158
+
159
+ frame.getContentPane().add(sample.sp, "Center");
160
+
161
+ frame.pack();
162
+
163
+ frame.setVisible(true);
164
+
165
+ }
166
+
167
+ }

1

誤字

2018/11/05 09:28

投稿

uyu
uyu

スコア12

test CHANGED
File without changes
test CHANGED
@@ -10,6 +10,8 @@
10
10
 
11
11
  パスワードを認証してOKを押したら家計簿の表が表示されるのが理想です。
12
12
 
13
- どなたかわかる人がいらっしゃましたら教えてください。
13
+ どなたかわかる人がいらっしゃましたら教えてください。
14
+
15
+ ちなみにプログラミングにはATOMを使用しています。
14
16
 
15
17
  よろしくお願いいたします。