2、通过编程读取指定文件组:如rivers的数据读取;
3、通过编程把读取的数据绘制在自编应用程序的界面上;
4、可通过鼠标右键或滚轮对鼠标选定位置进行放大,放大比例可调;
5、读取DBF对地图上的线进行标注,当标注内容为英文有中间有空格或标注为中文字符时,标注需要的每个词/字应保持一定距离(B/A/S级)
6、.鼠标左键点击地图上的线时,对该线进行查询,显示该线所对应的所有属性信息。(B/A/S级)
7、当标注文字相互间发生相互重叠时,将标注文字调整到非重叠且无歧义的位置。(S级)
这是读出来的图片
这是放大后的
我现在可以读出地图文件的所有点,还有图层的上下左右边界的值,但这些都是double型的数字,例如:图层的左上右下四个边界是 点也都是各种9位数十位数,这要怎么才能画出来?
6 个解决方案
#1
这问题太专业了,不明觉厉啊!
#2
public class test2_1 extends JFrame {
public static void main(String argv[]) {
ArrayList<Double> x = new ArrayList<Double>();
ArrayList<Double> y = new ArrayList<Double>();
test2_1 test = new test2_1();
test.readlay("D:/golang/mygo_project/src/test2/rivers.lay");
test.readidx("D:/golang/mygo_project/src/test2/rivers.idx");
test.readpts("D:/golang/mygo_project/src/test2/rivers.pts");
test.readcor("D:/golang/mygo_project/src/test2/rivers.cor", x, y);
test.readdbf("D:/golang/mygo_project/src/test2/rivers.dbf");
double[] x1 = new double[x.size()];
double[] y1 = new double[y.size()];
for (int i = 0; i < x.size(); i++) {
x1[i] = x.get(i);
}
for (int i = 0; i < x.size(); i++) {
y1[i] = y.get(i);
}
// System.out.println(x1[2]+","+y1[2]);
test.createWin();
}
public void createWin() {
// 设置标题
this.setTitle("地图读取");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// 设置大小可更改
this.setResizable(true);
// 设置大小
this.setSize(300, 100);
// 显示窗口
this.setVisible(true);
}
public void paint(Graphics g, Double[] x1, Double[] y1) {
// public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.translate(getWidth() / 2, getHeight() / 2);
g2d.setColor(Color.blue);
for (int i = 0; i < 377; i++) {
System.out.println(x1[i] + "," + y1[i]);
Line2D line = new Line2D.Double(x1[i] , y1[i] , x1[i + 1] , y1[i + 1] );// 创建line对象
g2d.draw(line);
}
}
我用这个方法为什么画出来的东西都不会显示
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.translate(getWidth() / 2, getHeight() / 2);
g2d.setColor(Color.blue);
g2d.drawLine(200, 0, 200, 0);
g2d.drawLine(0, -200, 0, 200);
g2d.fillRect(0, 0, 100, 100);
}
改成这样就会有东西显示在窗体里了?
#3
如果下面的代码可以满足你的要求,请自行百度SwingUtilities.invokeLater的原理。
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
Graphics2D g2d = (Graphics2D) g;
g2d.translate(getWidth() / 2, getHeight() / 2);
g2d.setColor(Color.blue);
g2d.drawLine(200, 0, 200, 0);
g2d.drawLine(0, -200, 0, 200);
g2d.fillRect(0, 0, 100, 100);
}
});
#4
我现在的问题就是有2个double型的数组,
通过这个方法画出来线段然后让它在窗体中显示,问题是显示不出来
public void paint(Graphics g, Double[] x1, Double[] y1) {
// public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.translate(getWidth() / 2, getHeight() / 2);
g2d.setColor(Color.blue);
for (int i = 0; i < 377; i++) {
System.out.println(x1[i] + "," + y1[i]);
Line2D line = new Line2D.Double(x1[i] , y1[i] , x1[i + 1] , y1[i + 1] );// 创建line对象
g2d.draw(line);
}
}
通过这个方法画出来线段然后让它在窗体中显示,问题是显示不出来
#5
类似于
代替
但用上面那个窗体中就没有东西,下面这个窗体中就会显示画出来的图和线
for (int i = 0; i < 377; i++) {
System.out.println(x1[i] + "," + y1[i]);
Line2D line = new Line2D.Double(x1[i] , y1[i] , x1[i + 1] , y1[i + 1] );
g2d.draw(line);
}
代替
g2d.drawLine(200, 0, 200, 0);
g2d.drawLine(0, -200, 0, 200);
g2d.fillRect(0, 0, 100, 100);
但用上面那个窗体中就没有东西,下面这个窗体中就会显示画出来的图和线
#6
其实就是如何向paint()中传参并将画出来的图显示在窗体中
#1
这问题太专业了,不明觉厉啊!
#2
public class test2_1 extends JFrame {
public static void main(String argv[]) {
ArrayList<Double> x = new ArrayList<Double>();
ArrayList<Double> y = new ArrayList<Double>();
test2_1 test = new test2_1();
test.readlay("D:/golang/mygo_project/src/test2/rivers.lay");
test.readidx("D:/golang/mygo_project/src/test2/rivers.idx");
test.readpts("D:/golang/mygo_project/src/test2/rivers.pts");
test.readcor("D:/golang/mygo_project/src/test2/rivers.cor", x, y);
test.readdbf("D:/golang/mygo_project/src/test2/rivers.dbf");
double[] x1 = new double[x.size()];
double[] y1 = new double[y.size()];
for (int i = 0; i < x.size(); i++) {
x1[i] = x.get(i);
}
for (int i = 0; i < x.size(); i++) {
y1[i] = y.get(i);
}
// System.out.println(x1[2]+","+y1[2]);
test.createWin();
}
public void createWin() {
// 设置标题
this.setTitle("地图读取");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// 设置大小可更改
this.setResizable(true);
// 设置大小
this.setSize(300, 100);
// 显示窗口
this.setVisible(true);
}
public void paint(Graphics g, Double[] x1, Double[] y1) {
// public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.translate(getWidth() / 2, getHeight() / 2);
g2d.setColor(Color.blue);
for (int i = 0; i < 377; i++) {
System.out.println(x1[i] + "," + y1[i]);
Line2D line = new Line2D.Double(x1[i] , y1[i] , x1[i + 1] , y1[i + 1] );// 创建line对象
g2d.draw(line);
}
}
我用这个方法为什么画出来的东西都不会显示
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.translate(getWidth() / 2, getHeight() / 2);
g2d.setColor(Color.blue);
g2d.drawLine(200, 0, 200, 0);
g2d.drawLine(0, -200, 0, 200);
g2d.fillRect(0, 0, 100, 100);
}
改成这样就会有东西显示在窗体里了?
#3
如果下面的代码可以满足你的要求,请自行百度SwingUtilities.invokeLater的原理。
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
Graphics2D g2d = (Graphics2D) g;
g2d.translate(getWidth() / 2, getHeight() / 2);
g2d.setColor(Color.blue);
g2d.drawLine(200, 0, 200, 0);
g2d.drawLine(0, -200, 0, 200);
g2d.fillRect(0, 0, 100, 100);
}
});
#4
我现在的问题就是有2个double型的数组,
通过这个方法画出来线段然后让它在窗体中显示,问题是显示不出来
public void paint(Graphics g, Double[] x1, Double[] y1) {
// public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.translate(getWidth() / 2, getHeight() / 2);
g2d.setColor(Color.blue);
for (int i = 0; i < 377; i++) {
System.out.println(x1[i] + "," + y1[i]);
Line2D line = new Line2D.Double(x1[i] , y1[i] , x1[i + 1] , y1[i + 1] );// 创建line对象
g2d.draw(line);
}
}
通过这个方法画出来线段然后让它在窗体中显示,问题是显示不出来
#5
类似于
代替
但用上面那个窗体中就没有东西,下面这个窗体中就会显示画出来的图和线
for (int i = 0; i < 377; i++) {
System.out.println(x1[i] + "," + y1[i]);
Line2D line = new Line2D.Double(x1[i] , y1[i] , x1[i + 1] , y1[i + 1] );
g2d.draw(line);
}
代替
g2d.drawLine(200, 0, 200, 0);
g2d.drawLine(0, -200, 0, 200);
g2d.fillRect(0, 0, 100, 100);
但用上面那个窗体中就没有东西,下面这个窗体中就会显示画出来的图和线
#6
其实就是如何向paint()中传参并将画出来的图显示在窗体中