我JDatePicker在我的应用程序中得到了工作,但希望将日期格式化为YYYY_MM_DD
当前日期的格式是默认值.Wed Jul 08 15:17:01 ADT 2015
在本指南中,有一个类格式化日期,如下所示.
package net.codejava.swing;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.JFormattedTextField.AbstractFormatter;
public class DateLabelFormatter extends AbstractFormatter {
private String datePattern = "yyyy-MM-dd";
private SimpleDateFormat dateFormatter = new SimpleDateFormat(datePattern);
@Override
public Object stringToValue(String text) throws ParseException {
return dateFormatter.parseObject(text);
}
@Override
public String valueToString(Object value) throws ParseException {
if (value != null) {
Calendar cal = (Calendar) value;
return dateFormatter.format(cal.getTime());
}
return "";
}
}
Run Code Online (Sandbox Code Playgroud)
所以我将类添加到我的包中,Swing应用程序具有适当的构造函数
JDatePickerImpl datePicker …Run Code Online (Sandbox Code Playgroud) 所以我有5000多个船舶坐标,它们是经度和纬度坐标.我想知道每艘船存放这些的最佳方法是什么.每艘船的坐标数量都是未知的.
最初我还在想一个类似的双2D数组:
double [][] array = new double[][];
Run Code Online (Sandbox Code Playgroud)
但我不知道我需要的尺寸.
我不知道是否Hashmap会工作,因为没有真正的"钥匙",我在想一个ArrayList中List的,但我不知道的实现,并且如果它是最可行的选择.
所以在 PostgreSQL 中,我有一堆长/纬度的几何值,其格式如下:
0101000020E610000095B9F94674CF37C09CBF0985083B5040
Run Code Online (Sandbox Code Playgroud)
因此,在 Postgres 中,我可以进行一个选择查询来格式化所有内容。
SELECT ST_AsText(position_geom)FROM reports;
Run Code Online (Sandbox Code Playgroud)
所以我安装了 postgreSQL 和 PostGIS JDBC 驱动程序eclipse,并认为我可以做类似的事情
rs = stmt.executeQuery("SELECT ST_AsText(*)FROM reports");
while(rs.next()){
String geomVal = rs.getString("position_geom");
System.out.println(geomVal);}
Run Code Online (Sandbox Code Playgroud)
但我收到错误:
function st_astext() does not exist.
Run Code Online (Sandbox Code Playgroud)
我已经导入了所有postGIS扩展,只是想知道是否有人有想法。
因此,当单击一个按钮时,我的方法返回一个字符串的arraylist,我试图在JtextArea中逐行显示字符串.这是我第一次在eclipse中玩GUI,但到目前为止我还在
JButton btnNewButton_1 = new JButton("Coordinate Anomalies");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
ArrayList<String> anomalies = vessels.coordinateAnomaly();
}
});
btnNewButton_1.setBounds(10, 45, 172, 23);
frame.getContentPane().add(btnNewButton_1);
JTextArea textArea = new JTextArea();
textArea.setBounds(10, 79, 172, 339);
frame.getContentPane().add(textArea);
Run Code Online (Sandbox Code Playgroud)
我以为我可能会做
JButton btnNewButton_1 = new JButton("Coordinate Anomalies");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
ArrayList<String> anomalies = vessels.coordinateAnomaly();
JTextArea textArea = new JTextArea();
textArea.setText(anomalies);
textArea.setBounds(10, 79, 172, 339);
frame.getContentPane().add(textArea);
}
});
Run Code Online (Sandbox Code Playgroud)
这绝对不起作用,如果它确实会在ArrayList格式中显示字符串,那么我应该有一个循环,但我有点迷失.
任何帮助都是极好的.
postgresql的新手,我有一个10,000,000行的表,我一次查询数百万行
SELECT mmsi, report_timestamp, position_geom, ST_X(position_geom) AS Long,ST_Y(position_geom) AS Lat
FROM reports4
WHERE position_geom IS NOT NULL
ORDER by report_timestamp ASC
LIMIT 1000000
OFFSET 8000000
Run Code Online (Sandbox Code Playgroud)
当我尝试查询最后几百万行时,没有任何显示
SELECT mmsi, report_timestamp, position_geom, ST_X(position_geom) AS Long,ST_Y(position_geom) AS Lat
FROM reports4
WHERE position_geom IS NOT NULL
ORDER by report_timestamp ASC
LIMIT 1000000
OFFSET 9000000
Run Code Online (Sandbox Code Playgroud)
不确定如果我正在进行查询,或者我正在忽略某些事情.
第一次用Java编写GUI
http://i58.tinypic.com/s13gh0.png
到目前为止,当我单击"坐标异常"时,JTextArea中会显示字符串的字符串,但查看文本的唯一方法是突出显示它.
我也尝试在JTextArea中添加滚动条,但没有运气.
JTextArea textArea = new JTextArea();
textArea.setBounds(10, 79, 172, 339);
frame.getContentPane().add(textArea);
JButton btnNewButton_1 = new JButton("Coordinate Anomalies");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ArrayList<String> anomalies = vessels.coordinateAnomaly();
JScrollPane jp = new JScrollPane();
jp.setViewportView(textArea);
for (String a : anomalies) {
textArea.append(a + "\n");
}
textArea.setBounds(10, 79, 172, 339);
frame.getContentPane().add(textArea);
}
});
btnNewButton_1.setBounds(10, 45, 172, 23);
frame.getContentPane().add(btnNewButton_1);
Run Code Online (Sandbox Code Playgroud)
这是我的代码(抱歉jank),不能强调我是GUI的新手,任何建议都非常感激.
我有一个字符串文件路径
String filePath = "/tmp/test/save/data/java/"
Run Code Online (Sandbox Code Playgroud)
并想删除最后 2 个目录和最后一个目录,/以便,
String filePath = "/tmp/test/save"
Run Code Online (Sandbox Code Playgroud)
我不想创建删除最后 10 个字符的子字符串,因为目录的长度可能会发生变化。
我正在考虑进行组合split(设置限制并删除最终索引),然后join使用分隔符重新创建字符串/,但想知道是否有更干净的方法?