I want to use JGo(for Swing) to develop a web application,but the drop and drag failure in Applet?
Why?
Because of the mechansim for applet or the JGo problem?
Thank you!
Here is my applet:
package net.cosmact.ui;
import javax.swing.JPanel;
import javax.swing.JApplet;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JSplitPane;
import com.nwoods.jgo.JGoBrush;
import com.nwoods.jgo.JGoView;
import com.nwoods.jgo.JGoPalette;
public class Viewer extends JApplet {
private JPanel jContentPane = null;
private JSplitPane jSplitPane = null;
private JGoPalette jGoPalette = null;
private JGoView jGoView = null;
/**
* This is the xxx default constructor
/
public Viewer() {
super();
}
/*
* This method initializes this
*
* @return void
/
public void init() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
}
/*
* This method initializes jContentPane
*
* @return javax.swing.JPanel
/
private JPanel getJContentPane() {
if (jContentPane == null) {
GridLayout gridLayout = new GridLayout();
gridLayout.setRows(1);
gridLayout.setColumns(2);
jContentPane = new JPanel();
jContentPane.setLayout(gridLayout);
jContentPane.add(getJSplitPane(), null);
}
return jContentPane;
}
/*
* This method initializes jSplitPane
*
* @return javax.swing.JSplitPane
/
private JSplitPane getJSplitPane() {
if (jSplitPane == null) {
jSplitPane = new JSplitPane();
jSplitPane.setLeftComponent(getJGoPalette());
jSplitPane.setRightComponent(getJGoView());
}
return jSplitPane;
}
/*
* This method initializes jGoPalette
*
* @return com.nwoods.jgo.JGoPalette
*/
private JGoPalette getJGoPalette() {
if (jGoPalette == null) {
jGoPalette = new JGoPalette();
jGoPalette.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
System.out.println(“mouseClicked()”); // TODO Auto-generated Event stub mouseClicked()
}
});
}
initPalette();
return jGoPalette;
}
private JGoView getJGoView(){
if(jGoView == null){
jGoView = new JGoView();
jGoView.addMouseListener(new MouseAdapter(){
@Override
public void mouseClicked(MouseEvent e) {
System.out.println(“JGoView are clicked”);
}
});
}
return jGoView;
}
private void initPalette(){
SampleNode bn=new SampleNode(“A”);
bn.setBrush(JGoBrush.blue);
jGoPalette.getDocument().addObjectAtTail(bn);
SampleNode bn1=new SampleNode(“B”);
bn1.setBrush(JGoBrush.red);
jGoPalette.getDocument().addObjectAtTail(bn1);
SampleNode bn2=new SampleNode(“C”);
bn2.setBrush(JGoBrush.green);
jGoPalette.getDocument().addObjectAtTail(bn2);
}
public void paint(Graphics g) {
System.out.println(“Paint method running…”);
g.setColor(Color.red);
g.setFont(new Font(“Helvetica”, Font.PLAIN, 24));
g.drawString(“InofCD欢迎您!”, 35, 65);
}
@Override
public void showStatus(String msg) {
System.out.println(“Show Status method running…”);
}
@Override
public void start() {
System.out.println(“Viewer start method running…”);
}
@Override
public void stop() {
System.out.println(“Viewer stop method running…”);
}
}
With older versions of the JRE, that was a bug. See Java Developer Connection bug 4225247.
Thanks.
But i am useing 1.5 version,also bug?
Than i want to know that can I use JGo to make a Applet ?
The only thing i need to do is calling JGoView.initializeDragDropHandling from JApplet.start?
Try copying/adapting the code in any of the examples that extend JApplet.
I had do it…but also can’t drop and drag.for test,i use the MultiTextNode(in example) instead of SampleNode when initialize Palette,but result is bad.
The JRE version is 1.5.0_10.
Code now:
package net.cosmact.ui;
import javax.swing.JPanel;
import javax.swing.JApplet;
import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import javax.swing.JSplitPane;
import com.nwoods.jgo.JGoBrush;
import com.nwoods.jgo.JGoView;
import com.nwoods.jgo.JGoPalette;
public class Viewer extends JApplet {
private JPanel jContentPane = null;
private JSplitPane jSplitPane = null;
private JGoPalette jGoPalette = null;
private JGoView jGoView = null;
/**
* This is the xxx default constructor
/
public Viewer() {
super();
}
/*
* This method initializes this
*
* @return void
/
public void init() {
//Execute a job on the event-dispatching thread:
//creating this applet’s GUI.
try {
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createGUI();
}
});
} catch (Exception e) {
System.err.println(“createGUI didn’t successfully complete”);
}
}
/*
* Create GUI for JApplet
* @author Liusu
/
private void createGUI() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
}
/*
* This method initializes jContentPane
*
* @return javax.swing.JPanel
/
private JPanel getJContentPane() {
if (jContentPane == null) {
GridLayout gridLayout = new GridLayout();
gridLayout.setRows(1);
gridLayout.setColumns(2);
jContentPane = new JPanel();
jContentPane.setLayout(gridLayout);
jContentPane.add(getJSplitPane(), null);
}
return jContentPane;
}
/*
* This method initializes jSplitPane
*
* @return javax.swing.JSplitPane
/
private JSplitPane getJSplitPane() {
if (jSplitPane == null) {
jSplitPane = new JSplitPane();
jSplitPane.setLeftComponent(getJGoPalette());
jSplitPane.setRightComponent(getJGoView());
}
return jSplitPane;
}
/*
* This method initializes jGoPalette
*
* @return com.nwoods.jgo.JGoPalette
*/
private JGoPalette getJGoPalette() {
if (jGoPalette == null) {
jGoPalette = new JGoPalette();
jGoPalette.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
System.out.println(“mouseClicked()”); // TODO Auto-generated Event stub mouseClicked()
}
});
}
initPalette();
return jGoPalette;
}
private JGoView getJGoView() {
if (jGoView == null) {
jGoView = new JGoView();
jGoView.initializeDragDropHandling();
}
return jGoView;
}
private void initPalette() {
SampleNode bn = new SampleNode(“A”);
bn.setBrush(JGoBrush.blue);
jGoPalette.getDocument().addObjectAtTail(bn);
SampleNode bn1 = new SampleNode(“B”);
bn1.setBrush(JGoBrush.red);
jGoPalette.getDocument().addObjectAtTail(bn1);
SampleNode bn2 = new SampleNode(“C”);
bn2.setBrush(JGoBrush.green);
jGoPalette.getDocument().addObjectAtTail(bn2);
}
@Override
public void showStatus(String msg) {
System.out.println(“Show Status method running…”);
}
@Override
public void start() {
System.out.println(“Viewer start method running…”);
jGoView.initializeDragDropHandling();
}
@Override
public void stop() {
System.out.println(“Viewer stop method running…”);
}
}