G
Gast
Gast
wie kann ich mit dem folgendem code die svg gleich beim starten laden???
Code:
import java.awt.*;
import javax.swing.*;
import javax.*;
import java.awt.event.*;
import java.io.*;
import org.apache.batik.swing.JSVGCanvas;
import org.apache.batik.swing.gvt.GVTTreeRendererAdapter;
import org.apache.batik.swing.gvt.GVTTreeRendererEvent;
import org.apache.batik.swing.svg.SVGDocumentLoaderAdapter;
import org.apache.batik.swing.svg.SVGDocumentLoaderEvent;
import org.apache.batik.swing.svg.GVTTreeBuilderAdapter;
import org.apache.batik.swing.svg.GVTTreeBuilderEvent;
public class MyFirstTest extends JFrame
{
private JButton down;
private JButton left;
private JButton right;
private JButton zoomin;
private JButton up;
private JButton zoomout;
private JPanel panel;
private JLabel middle;
private JLabel seethat;
private JButton nothing;
public MyFirstTest()
{
super("Navigatiossystem als JAVA-Applikation");
setLocation(112,83);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setLayout(new BorderLayout(2,1));
setSize(800,600);
setBackground(Color.black);
setForeground(Color.white);
up = new JButton("\u25C4");
down = new JButton("\u25B2");
left = new JButton("\u25BA");
right = new JButton("\u25BC");
zoomin = new JButton("+");
zoomout = new JButton("-");
nothing = new JButton("SVG");
JPanel panel = new JPanel(new GridLayout(2,1));
up.setBounds(600,150,50,50);
down.setBounds(650,100,50,50);
left.setBounds(700,150,50,50);
right.setBounds(650,200,50,50);
zoomin.setBounds(625,300,50,50);
zoomout.setBounds(675,300,50,50);
nothing.setBounds(625,400,75,75);
this.getContentPane().add(up);
this.getContentPane().add(down);
this.getContentPane().add(left);
this.getContentPane().add(right);
this.getContentPane().add(zoomin);
this.getContentPane().add(zoomout);
this.getContentPane().add(nothing);
addButtonListener(up);
addButtonListener(down);
addButtonListener(left);
addButtonListener(right);
addButtonListener(zoomin);
addButtonListener(zoomout);
addButtonListener(nothing);
//middle = new JLabel("Navigatiossystem als JAVA-Applikation");
//middle.setHorizontalAllignment(JLabel.???);
seethat = new JLabel("Button Click");
//getContentPane().add(BorderLayout.WEST, middle);
getContentPane().add(seethat);
getContentPane().add(BorderLayout.EAST, panel);
setVisible(true);
JFrame frame;
JButton button = new JButton("Load SVG...");
JLabel label = new JLabel();
JSVGCanvas SVGCanvas = new JSVGCanvas();
}
public static void main(String[] args)
{
MyFirstTest frm = new MyFirstTest();
SVGApplication app = new SVGApplication(frm);
frm.getContentPane().add(app.createComponents());
frm.addWindowListener(new WindowAdapter()
{
public void WindowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
/* vielleicht oberhalb von main
public SVGApplication(JFrame frm)
{
Frame = frm;
}
*/
private void addButtonListener(JButton b)
{
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
eingabe(ae.getActionCommand());
}
});
}
public JComponent createComponents()
{
final JPanel Panel = new JPanel(new BorderLayout());
JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
this.getContentPane().add(p);
panel.add("RIGHT", p);
panel.add("LEFT", svgCanvas);
button.addActionListener(new ActionListener())
{
public void ActionPerformed(ActionEvent ae)
{
JFileChooser fc = new JFileChooser(".");
int choise = fc.showOpenDialog(panel);
if (choise == JFileChooser.APPROVE_OPTION)
{
File f = fc.getSelectedFile();
try
{
svgCanvas.setURI(frm.toURL().toString());
} catch (IOException ex)
{
ex.printStackTrace();
}
}
}
});
//Kopie
svgCanvas.addSVGDocumentLoaderListener(new SVGDocumentLoaderAdapter() {
public void documentLoadingStarted(SVGDocumentLoaderEvent e) {
label.setText("Document Loading...");
}
public void documentLoadingCompleted(SVGDocumentLoaderEvent e) {
label.setText("Document Loaded.");
}
});
svgCanvas.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() {
public void gvtBuildStarted(GVTTreeBuilderEvent e) {
label.setText("Build Started...");
}
public void gvtBuildCompleted(GVTTreeBuilderEvent e) {
label.setText("Build Done.");
//frame.pack();
}
});
svgCanvas.addGVTTreeRendererListener(new GVTTreeRendererAdapter() {
public void gvtRenderingPrepare(GVTTreeRendererEvent e) {
label.setText("Rendering Started...");
}
public void gvtRenderingCompleted(GVTTreeRendererEvent e) {
label.setText("");
}
});
return panel;
}
private void eingabe(String a)
{
if (a=="\u25C4")
{
seethat.setText("Links");
}
if (a=="\u25B2")
{
seethat.setText("Oben");
}
if (a=="\u25BA")
{
seethat.setText("Rechts");
}
if (a=="\u25BC")
{
seethat.setText("Unten");
}
if (a=="+")
{
seethat.setText("Zoom In");
}
if (a=="-")
{
seethat.setText("Zoom Out");
}
if (a=="SVG")
{
seethat.setText("");
}
}
}