-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathxm1.java
138 lines (123 loc) · 4.91 KB
/
xm1.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
131
132
133
134
135
136
137
138
package finalproject;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import javaproject.boatregistration;
import javaproject.ownerpg;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DealerPage extends JFrame {
private JPanel contentPane;
public DealerPage() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 775, 440);
contentPane = new JPanel();
contentPane.setBackground(new Color(137, 209, 194));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton addboat = new JButton("Add Car");
addboat.setFont(new Font("Verdana", Font.PLAIN, 18));
addboat.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
CarRegistration br = new CarRegistration();
br.setVisible(true);
dispose();
}
});
addboat.setBounds(271, 100, 163, 46);
addboat.setBackground(new Color(248, 151, 29));
addboat.setBorder(null);
addboat.setForeground(new Color(255,255,255));
contentPane.add(addboat);
JButton btnDelete = new JButton("Delete");
btnDelete.setFont(new Font("Verdana", Font.PLAIN, 18));
btnDelete.setBounds(271, 200, 163, 46);
btnDelete.setBackground(new Color(248, 151, 29));
btnDelete.setForeground(new Color(255, 255, 255));
btnDelete.setBorder(null);
contentPane.add(btnDelete);
JLabel lblNewLabel = new JLabel("Dealer Page");
lblNewLabel.setFont(new Font("Verdana", Font.PLAIN, 26));
lblNewLabel.setForeground(new Color(248, 151, 29));
lblNewLabel.setBounds(271, 25, 224, 30);
contentPane.add(lblNewLabel);
JButton btnNewButton = new JButton("Car Details");
/*
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/houseboat","postgres","Rkp@1801");
String query = "SELECT * FROM boat_registration";
java.sql.Statement stm = connection.createStatement();
ResultSet res = stm.executeQuery(query);
String columns[] = { "username", "boat_id", "model" };
String data[][] = new String[8][3];
int i = 0;
while (res.next()) {
String id = res.getString("username");
String nom = res.getString("boat_id");
String model = res.getString("model");
data[i][0] = id + "";
data[i][1] = nom;
data[i][2] = model;
i++;
}
DefaultTableModel model = new DefaultTableModel(data, columns);
JTable table = new JTable(model);
table.setShowGrid(true);
table.setShowVerticalLines(true);
JScrollPane pane = new JScrollPane(table);
JFrame f = new JFrame("Populate JTable from Database");
JPanel panel = new JPanel();
panel.add(pane);
f.getContentPane().add(panel);
f.setSize(500, 250);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
} catch (HeadlessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
*/
btnNewButton.setFont(new Font("Verdana", Font.PLAIN, 18));
btnNewButton.setBounds(271, 300, 163, 46);
btnNewButton.setBackground(new Color(248, 151, 29));
btnNewButton.setForeground(new Color(255,255,255));
btnNewButton.setBorder(null);
contentPane.add(btnNewButton);
}
public static void main(String[] args) {
String jdbcURL = "jdbc:postgresql://localhost:5432/houseboat";
String username = "postgres";
String password = "subbu0456";
try {
Connection connection = DriverManager.getConnection(jdbcURL, username, password);
System.out.print("Connected");
}
catch(SQLException e) {
System.out.println("Error in connection");
e.printStackTrace();
}
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
DealerPage frame = new DealerPage();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}