Сообщение было отмечено totlant как решение
Решение
поясню кодом: мейн: | Java | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| package diplomawork;
public class MainDiploma {
public static void main(String[] args) {
ExpertTableForm c=new ExpertTableForm("Making New questions");
c.setVisible(true);
}
} |
|
рисует десктоп: | Java | 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
| package diplomawork;
import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
import javax.swing.DefaultDesktopManager;
public class RealizedIMainFrame extends JFrame implements IMainFrame{
/**
*
*/
protected String url="jdbc:oracle:thin:@tlayshev:1521:TEST",
login="TESTER",
password="qwe123",
query="SELECT ADVISES FROM TESTER.DIPLOMA WHERE ID >=?",
query2="SELECT QUESTIONS FROM TESTER.DIPLOMA",
query3="SELECT ID,QUESTIONS,ADVISES FROM TESTER.DIPLOMA",
query4="INSERT INTO TESTER.DIPLOMA (ID, QUESTIONS, ADVISES) VALUES (?, ?, ?)",
query5="SELECT ID FROM TESTER.DIPLOMA",
empty="";
protected int lastID;
protected int nextID;
List<String> querylist = new ArrayList<String>();
List<String> querylist2 = new ArrayList<String>();
List<Integer> querylist3 = new ArrayList<Integer>();
Connection con;
public void init(){
try {
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
}
catch (Exception e) {
e.printStackTrace();
}
}
public List<String> GetAdvise(){
ResultSet rs = null;
try{
if(con==null){
con= DriverManager.getConnection(url, login, password);
}
PreparedStatement pstmt = con.prepareStatement(query);
pstmt.setInt(1, 1);
rs = pstmt.executeQuery();
while (rs.next()) {
/*String str = rs.getString(1);
System.out.println(str);
querylist.add(str);*/
querylist.add(rs.getString("ADVISES"));
}
}
catch (SQLException e) {
e.printStackTrace();
}
return querylist;
}
public List<String> GetQuestion(){
ResultSet rs = null;
try{
if(con==null){
con= DriverManager.getConnection(url, login, password);
}
Statement pstmt = con.createStatement();
//pstmt.setInt(1, 1);
rs = pstmt.executeQuery(query2);
while (rs.next()) {
querylist2.add(rs.getString("QUESTIONS"));
}
}
catch (SQLException e) {
e.printStackTrace();
}
return querylist2;
}
public int GetLastID(){
ResultSet rs = null;
try{
if(con==null){
con= DriverManager.getConnection(url, login, password);
}
PreparedStatement pstmt = con.prepareStatement(query5);
rs = pstmt.executeQuery();
while (rs.next()) {
querylist3.add(rs.getInt("ID"));
}
}
catch (SQLException e) {
e.printStackTrace();
}
lastID=querylist3.get(querylist3.size()-1)+1;
return lastID;
}
private static final long serialVersionUID = 1L;
protected JDesktopPane dp=new JDesktopPane();
protected DefaultDesktopManager dm=new DefaultDesktopManager();
RealizedIMainFrame(){
setContentPane(dp);
setSize(1000, 800);
dp.setDesktopManager(dm);
}
} |
|
рисует 1 фрейм: | Java | 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
| package diplomawork;
import java.awt.*;
import java.awt.event.*;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
public class TestCaseForm extends RealizedIMainFrame{
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel buttonPanel=new JPanel();
private JPanel boxesPanel = new JPanel();
private JButton button = new JButton("Reload");
private List<JCheckBox> checkBoxArray = new ArrayList<JCheckBox>();
private List<JLabel> LabelOfCh= new ArrayList<JLabel>();
private List<String> QuestionQuerylist=(List<String>) GetQuestion();
private List<String> AdviseQuerylist=(List<String>) GetAdvise();
private int sizeofframe=QuestionQuerylist.size()*50;
private JScrollPane sp=new JScrollPane();
private JInternalFrame ifr2=new JInternalFrame("Test Case set", true, true, true, true);
private class ReloadActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
// ExpertTableForm c=new ExpertTableForm("Making New questions");
//c.setVisible(true);
}
}
private ActionListener actionListener = new ActionListener() {
@Override public void actionPerformed(ActionEvent actionEvent) {
init();
for(int i = 0; i < GetLastID(); i++) {
((AbstractButton) checkBoxArray.get(i)).setText( ((AbstractButton) checkBoxArray.get(i)).isSelected() ?
AdviseQuerylist.get(i) : empty);
}
}
};
TestCaseForm(String s){
super();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
try {
con = DriverManager.getConnection(url, login, password);
} catch (SQLException e) {
e.printStackTrace();
}
ifr2.setBounds(0, 10, 300, sizeofframe);
ifr2.setVisible(true);
dp.add(ifr2);
ifr2.getAutoscrolls();
JPanel boxesPanel = new JPanel();
boxesPanel.setLayout(new BoxLayout(boxesPanel, BoxLayout.Y_AXIS));
ifr2.getContentPane().add(boxesPanel, BorderLayout.PAGE_START);
for(int j = 0; j < QuestionQuerylist.size(); j++)
{
JCheckBox checkBox = new JCheckBox();
JLabel LcheckBox = new JLabel();
LcheckBox.setLabelFor(checkBox);
LcheckBox.setText(QuestionQuerylist.get(j));
checkBoxArray.add(checkBox);
LabelOfCh.add(LcheckBox);
}
for(int i = 0; i< checkBoxArray.size(); i++) {
boxesPanel.add(LabelOfCh.get(i));
boxesPanel.add(checkBoxArray.get(i));
checkBoxArray.get(i).addActionListener(actionListener);
checkBoxArray.get(i).setMnemonic(KeyEvent.VK_S);
checkBoxArray.get(i).setVisible(true);
}
boxesPanel.add(sp);
ifr2.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
ActionListener actionListener2 = new ReloadActionListener();
button.addActionListener(actionListener2);
button.setVisible(true);
buttonPanel.add(button);
}
} |
|
рисует 2 фрейм: | Java | 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
| package diplomawork;
import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.swing.*;
public class ExpertTableForm extends TestCaseForm{
/**
*
*/
private JInternalFrame ifr2=new JInternalFrame("Expert table", true, true, true, true);
private static final long serialVersionUID = 1L;
private JPanel boxesPanel2 = new JPanel();
private JPanel buttonPanel=new JPanel();
private JButton button = new JButton("Create");
private JButton button2 = new JButton("Save");
private JTextField tf= new JTextField(20);
private JTextArea ta=new JTextArea(5, 30);
private JScrollPane sp=new JScrollPane(ta);
private String stf;
private String sta;
static int bc=1;
public class CreateActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
//Код, который нужно выполнить при нажатии
boxesPanel2.add(tf);
tf.setVisible(true);
boxesPanel2.add(ta);
ta.setVisible(true);
boxesPanel2.add(sp);
sp.setVisible(true);
button.setEnabled(false);
ifr2.validate();
ifr2.repaint();
button2.setEnabled(true);
}
}
public int NextID(){
ResultSet rs = null;
try{
if(con==null){
con= DriverManager.getConnection(url, login, password);
}
PreparedStatement pstmt = con.prepareStatement(query5);
rs = pstmt.executeQuery();
while (rs.next()) {
querylist3.add(rs.getInt("ID"));
}
}
catch (SQLException e) {
e.printStackTrace();
}
nextID=querylist3.get(querylist3.size()-1)+bc;
return nextID;
}
public class SaveActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
stf=tf.getText();
sta=ta.getText();
ResultSet rs = null;
try{
if(con==null){
con= DriverManager.getConnection(url, login, password);
}
PreparedStatement pstmt = con.prepareStatement(query4);
pstmt.setInt(1, NextID());
pstmt.setString(2, stf);
pstmt.setString(3, sta);
rs = pstmt.executeQuery();
}
catch (SQLException eI) {
eI.printStackTrace();
}
ifr2.revalidate();
ifr2.repaint();
ifr2.updateUI();
}
}
ExpertTableForm(String s) {
super(s);
init();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setContentPane(dp);
ifr2.setBounds(510, 10, 400, 300);
ifr2.setVisible(true);
dp.add(ifr2);
ifr2.getContentPane().add(boxesPanel2, BorderLayout.PAGE_START);
boxesPanel2.setLayout(new BoxLayout(boxesPanel2, BoxLayout.Y_AXIS));
ifr2.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
ActionListener actionListener = new CreateActionListener();
button.addActionListener(actionListener);
button.setVisible(true);
ActionListener actionListener2 = new SaveActionListener();
button2.addActionListener(actionListener2);
button2.setVisible(true);
button2.setEnabled(false);
//button.setBounds(20,20,250,70);
buttonPanel.add(button);
buttonPanel.add(button2);
}
} |
|
не хочет после добавление данных во 2 фрейм менять 1. Пробовал методы .updateUI, ifr2.validate();
ifr2.repaint(); не помогают
0
|