Hallo!
Mit folgende Java-code bekomme ich ein ganz normales Datum (jahr-monat-tag std:min:sec.0). Hier der Code
(Siehe Zeile 159 - 162)
Nun möchte ich die Ausgabe in Format: TT-MM-JJJJ haben. Wie kann ich das Programm umschreiben?
Danke im Voraus
Mit folgende Java-code bekomme ich ein ganz normales Datum (jahr-monat-tag std:min:sec.0). Hier der Code
(Siehe Zeile 159 - 162)
Java:
package gui.dialog ;
import java.sql.ResultSet;
import gui.MainFrame;
import gui.panel.CPProjectList;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JTextField;
import com.jgoodies.forms.builder.PanelBuilder;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import model.ProjectListTableModel;
import utilities.DatabaseConnection;
public class DialogProjectEdit extends JDialog {
private MainFrame frame = MainFrame.getInstance();
private DatabaseConnection dbc = frame.getConnectedDB();
private int projId = 0;
private JButton btEdit;
private JButton btCancel;
private JTextField projektName;
private JTextField projektId;
private JTextField createdDate;
public DialogProjectEdit(JFrame frame, boolean modal, int i){
super(frame, modal);
this.setProjId(i);
initialize();
setModal(modal);
this.setLocationRelativeTo(null);
}
private void initialize() {
this.setTitle("Projekt Ändern");
this.setSize(450, 180);
FormLayout layout = new FormLayout(
"right:[40dlu,pref], 3dlu, 40dlu, 7dlu, "
+ "right:[40dlu,pref], 3dlu, 60dlu",
"p, 3dlu, p, 3dlu, p, 9dlu, p, 3dlu, p, 14dlu, p");
PanelBuilder builder = new PanelBuilder(layout);
builder.setDefaultDialogBorder();
CellConstraints cc = new CellConstraints();
int row = 1;
builder.addLabel("Projektname:", cc.xy(1, row));
builder.add(getPName(), cc.xyw(3, row++, 5));
row++;
builder.addLabel("ProjektID:", cc.xy(1, row));
builder.add(getPId(), cc.xyw(3, row++, 5));
row++;
builder.addLabel("Erstellt am", cc.xy(1, row));
builder.add(getCDate(), cc.xyw(3, row++, 5));
row++;
builder.add(getbtEdit(), cc.xy(5, row));
builder.add(getbtCancel(), cc.xy(7, row));
this.getValues();
this.setContentPane(builder.getPanel());
}
private void getValues(){
try{
ResultSet rs = dbc.abfrage("select * from project_table where project_id = "+ this.getProjId() +" ;");
while( rs.next() ) {
this.projektId.setText(rs.getString(1));
this.projektName.setText(rs.getString(2));
this.createdDate.setText(rs.getString(3));}
} catch (Exception e) {
e.printStackTrace();
}
}
private void setProjId(int i){
this.projId = i + 1;
}
private int getProjId(){
return this.projId;
}
/**
* This method initializes tfName
*
* @return javax.swing.JTextField
*/
private JTextField getPName() {
if (projektName == null) {
projektName = new JTextField();
}
return projektName;
}
/**
* This method initializes tfName
*
* @return javax.swing.JTextField
*/
private JTextField getPId() {
if (projektId == null) {
projektId = new JTextField();
}
return projektId;
}
/**
* This method initializes tfName
*
* @return javax.swing.JTextField
*/
private JTextField getCDate() {
if (createdDate == null) {
createdDate = new JTextField();
}
return createdDate;
}
/**
* This method initializes btEdit
*
* @return javax.swing.JButton
*/
private JButton getbtEdit() {
if (btEdit == null) {
btEdit = new JButton();
btEdit.setText("Ändern");
final int id = this.getProjId();
btEdit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
String query = "UPDATE project_table " +
"set created_date = \'"
+ createdDate.getText() + "\' WHERE project_id = "+ id +";";
if(dbc.setEintrag(query))
System.out.println("Query Successed");
DialogProjectEdit.this.setVisible(false);
DialogProjectEdit.this.dispose();
frame.loadPanel(new CPProjectList());
}
});
}
return btEdit;
}
/**
* This method initializes btCancel
*
* @return javax.swing.JButton
*/
private JButton getbtCancel() {
if (btCancel == null) {
btCancel = new JButton();
btCancel.setText("Abbrechen");
btCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
DialogProjectEdit.this.setVisible(false);
DialogProjectEdit.this.dispose();
}
});
}
return btCancel;
}
}
Nun möchte ich die Ausgabe in Format: TT-MM-JJJJ haben. Wie kann ich das Programm umschreiben?
Danke im Voraus