Problem in setCursor as WAIT_CURSOR
I have one swing application in which cursor is changed through setCursor() at every action_performed. My problem is if When some process is going on the Cursor changes successfully to Wait Cursor but if during the process if i move cursor to the Title of appilcation frame it changes to the default cursor and when i move cursor again back to the working screen it remains as default cursor only, though process is continue. So instead of again change to WAIT_CURSOR cursor remains as Default Cursor only
* WaitCursor_Test.java
import album.*;
import java.awt.*;
import javax.swing.*;
public class WaitCursor_Test extends JFrame {
public WaitCursor_Test() {
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setSize(400,300);
setLocationRelativeTo(null);
setTitle("Wait 10 seconds");
worker = new SwingWorker() {
public Object construct() {
setCursor(new Cursor(Cursor.WAIT_CURSOR));
try{Thread.sleep(10000);}catch(InterruptedException ex){}
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
setTitle("Done");
return null;
worker.start();
public static void main(final String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
new WaitCursor_Test().setVisible(true);
You can download the latest release of the SwingWorker project.
https://swingworker.dev.java.net/servlets/ProjectDocumentList
private SwingWorker worker ;
}
Similar Messages
-
Problem with setCursor for JButton in cell on JTable
i have a problem with setCursor to JButton that is in a cell of the JTable}
this is the code
public class JButtonCellRenderer extends JButton implements TableCellRenderer {
public JButtonCellRenderer() {
setOpaque(true);
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus,
int row, int column) {
if (isSelected) {
setForeground(table.getSelectionForeground());
setBackground(table.getSelectionBackground());
else {
setForeground(table.getForeground());
setBackground(Color.WHITE);
setBorder(null);
if(table.getValueAt(row,column) == null){
setText("");
if(isSelected){
setBackground(table.getSelectionBackground());
}else{
setBackground(Color.WHITE);
}else{
if(table.getValueAt(row,column) instanceof JButton){
JButton _button = (JButton)table.getValueAt(row,column);
if(_button.getText().trim().equals("")){
setText("<html>"+ "<font size=\"3\" COLOR=\"#0000FF\"><u><b>Ver...</b></u></font>"+"");
}else{
setText("<html>"+ "<font size=\"3\" COLOR=\"#0000FF\"><u><b>" + _button.getText() + "</b></u></font>"+"");
return this;
}Not quite sure I understand the problem, but I guess you have tried to call setCursor on your renderer and found it didn't work? The reason, I think, is that the renderer only renders a JButton. The thing that ends up in the table is in fact only a "picture" of a JButton, and among other things it won't receive and interact with any events, such as MouseEvents (so it wouldn't know that the cursor should change).
There are at least two alternatives for you: You can perhaps use a CellEditor instead of a CellRenderer. Or you can add a MouseListener to the table and then use the methods column/rowAtPoint to figure out if the cursor is over your JButton cell and change the cursor yourself if it is. -
Hi all I need to change the mouse icon.
I'm using:
setCursor(Cursor.WAIT_CURSOR);
buet the problem is that this only works inside the application. If the mouse cursors does out of the application (f.e. to the windows desk) the mouse changes into the typical arrow icon.
What I need is the mouse icon to remain as a sand-watch icon till some opperations are done in the application.
Thanks in advance.
Dani.I believe this behaviour is controlled by the operating system. This is part of the pre-emptive multi-tasking system, the principle being that one busy application should not disrupt the rest of the OS (compare with Win 3.1).
So I don't think you can do that, and even if you can, you probably shouldn't
HTH -
Changing wait cursor in netbeans.
Hi,
I'm having problems trying to change my cursor, I'm using netbeans and i want to change the cursor when a task is been doing.
I have a frameview and will show you the code. But i'm getting a error using setCursor().
I tried using a Jframe instead of a FrameView and this code works ok. Who knows why i can't use setCursor() with a FrameView?
Thanks for your help
public class ProgressBarDemo extends FrameView
private Task task;
class Task extends SwingWorker<Void, Void> {
@Override
public Void doInBackground() {
Random random = new Random();
int progress = 0;
//Initialize progress property.
setProgress(0);
while (progress < 100) {
//Sleep for up to one second.
try {
Thread.sleep(random.nextInt(1000));
} catch (InterruptedException ignore) {}
//Make random progress.
progress += random.nextInt(10);
setProgress(Math.min(progress, 100));
return null;
@Override
public void done() {
Toolkit.getDefaultToolkit().beep();
startButton.setEnabled(true);
setCursor(null); //turn off the wait cursor
taskOutput.append("Done!\n");
/** Creates new form ProgressBarDemo */
public ProgressBarDemo() {
initComponents();
private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {
startButton.setEnabled(false);
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
//Instances of javax.swing.SwingWorker are not reusuable, so
//we create new instances as needed.
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ProgressBarDemo().setVisible(true);
}So, you are talking about Swing application Framework???
It would certainly not work because 'FrameView' is neither a Frame, nor a Panel, etc. , I don't think NetBeans would allow you to compile such a code.
See you can use:
there is an '.........App' class,( for your case it may be ProgressBarDemoApp, but I doubt it), use its static method to obtain refrence to mainframe like this:
JFrame frm= ProgressBarDemoApp.getApplication().getMainFrame();
frm.setCursor(Cursor.WAIT_CURSOR);Another possibility is:
NetBeans make a default main panel in View named 'mainPanel', you can set its default cursor:
mainPanel.setCursor(Cursor.WAIT_CURSOR);hope it works............
Thanks! -
warning at:
this.setCursor(Cursor.WAIT_CURSOR);
this.setCursor(Cursor.DEFAULT_CURSOR);
what's the new method?This is where the APIs come in handy...
They'll tell you that setCurso is inherited from java.awt.frame, an d when you look at the method description it says it's replaced by Component.setCursor... so probably you'll need to take a look at JComponent and Component in the APIs to know what to do.
Good luck -
I want to link a button to a web page
making a button and adding ActionListener to it is ok from there how do i proceed.
Thanks.import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
public class URL_Demo extends JFrame {
public URL_Demo() {
initComponents();
private void initComponents() {
setTitle("URL Connect");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
toolbar = new JPanel();
tabbedpane = new JTabbedPane();
combobox = new JComboBox();
combobox.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
"http://news.bbc.co.uk/sport1/hi/football/teams/a/arsenal/default.stm" ,
"http://www.amazon.com/",
"http://www.jackinworld.com/",
combobox.setPreferredSize(new java.awt.Dimension(500, 22));
combobox.setSelectedIndex(0);
combobox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
displayPage();
toolbar.add(combobox);
getContentPane().add(toolbar, BorderLayout.NORTH);
getContentPane().add(tabbedpane);
setExtendedState(JFrame.MAXIMIZED_BOTH);
setVisible(true);
displayPage();
private void displayPage() {
urlString = combobox.getSelectedItem().toString();
setCursor(Cursor.WAIT_CURSOR);
URL url = null;
InputStream input = null;
try{
url = new URL( urlString );
}catch(MalformedURLException ex){
ex.printStackTrace();
StringBuffer strb = null;
try{
try{
input = url.openStream();
}catch(UnknownHostException ex){
if( input != null ){
int c = input.read();
strb = new StringBuffer();
while( c != -1 ){
char cc = (char)c;
strb.append(cc);
c = input.read();
}catch(IOException ex){
ex.printStackTrace();
scrollpane = new JScrollPane();
tabbedpane.add(scrollpane);
tabbedpane.setTitleAt(count++, urlString);
editorpane = new JEditorPane();
editorpane.setEditable(false);
editorpane.setContentType("text/html");
scrollpane.setViewportView(editorpane);
if( strb != null ){
editorpane.setText(strb.toString());
}else{
Toolkit.getDefaultToolkit().beep();
String htmlText =
"<html>"
+"<body BGCOLOR=\"#ffffe0\">"
+"<br>Connection failed: <br> " +urlString+
"<br><br>Make sure you are connected to the Internet"
+"</body>"
+"</html>";
editorpane.setText(htmlText);
setCursor(Cursor.DEFAULT_CURSOR);
public static void main(String args[]) {
new URL_Demo();
private String urlString;
private JEditorPane editorpane;
private JPanel toolbar;
private JTabbedPane tabbedpane;
private JComboBox combobox;
private JScrollPane scrollpane;
private int count;
} -
How to create rotating cursor and wait symbol?
hello,
I am creating one frame and from hat frame I call nother panel. It takes some time to display (30 seconds).
So, I need to display some stuff that tell please wait some time like messages in some blink sytuff and also the cusor must be rotatable.
how can i do?.Hi Ramesh;
you can display wait cursor by using setCursor(Cursor.WAIT_CURSOR) method on your frame object. -
Changing cursor when launching table editor
I have a complex editor for a certain type of data in my table. This editor takes a few seconds to launch so i want the table cursor to change to the wait cursor while it launches. I have created a class extending the DefaultCellEditor and in the getTableCellEditorComponent i have the following...
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,int row, int column) {
table.setCursor(Cursor.WAIT_CURSOR);
//cast the value into a Molecule object
currentMol = (Molecule)value;
//launch my editor
SingleMoleculeView smv= new SingleMoleculeView(currentMol.getProperty("Smiles"),"Edit");
table.setCursor(Cursor.DEFAULT_CURSOR);
return smv; //editorComponent;
}However i get the error
Error(354,19): method setCursor(int) not found in class javax.swing.JTable
Anyone have any ideas how a can get this to work ?The code compiles fine now i use new Cursor(Cursor.WAIT_CURSOR), however, the cursor doesn't actually change at all, not sure what to do, any ideas ?
My table is in a JInternalFrame if that has any bearing.
Thanks -
SetCursor(WAIT_CURSOR) on a title bar
I am having trouble getting my cursor to remain the WAIT_CURSOR on my window. I initially had problems getting the cursor to stay WAIT_CURSOR as the user moved the mouse around on the window itself, but I solved that problem by calling setCursor on all the seperate components of the window. (see code below). The only component left that has this problem now seems to be the title bar. As soon as the user moves the mouse up to the title bar while the process is running, the cursor immediately goes back to the default cursor. Here is my code:
private void setCursorStateFile(Cursor inCursor)
setCursor(inCursor);
parentFrame.setCursor(inCursor);
parentFrame.getMainMenu().setCursor(inCursor);
parentFrame.getBrowseToolBar().setCursor(inCursor);
jPanelQuery.setCursor(inCursor);
jTextFieldCPT.setCursor(inCursor);
jTextFieldDescription.setCursor(inCursor);
jTextFieldStateFile.setCursor(inCursor);
jTextFieldStatusDate.setCursor(inCursor);
I don't know if I was headed down the right path or not, but the other thing I tried was to define my own UI for the JInternalFrame which I inherited from BasicInternalFrameUI which allowed me to define a getTitlePane() method. Using that method I called setCursor on the titlePane. Didn't work however.
Thanks in advance for any help!Thanks for your reply. I gave your suggestion a try and unfortunately it didn't work for my problem. It seems that my problem is that I just candle get a handle on the title bar so that I can call setCursor on it. Does anyone know how to do that or if that is even possible?
-
Problem with JFrame and busy/wait Cursor
Hi -- I'm trying to set a JFrame's cursor to be the busy cursor,
for the duration of some operation (usually just a few seconds).
I can get it to work in some situations, but not others.
Timing does seem to be an issue.
There are thousands of posts on the BugParade, but
in general Sun indicates this is not a bug. I just need
a work-around.
I've written a test program below to demonstrate the problem.
I have the problem on Solaris, running with both J2SE 1.3 and 1.4.
I have not tested on Windows yet.
When you run the following code, three JFrames will be opened,
each with the same 5 buttons. The first "F1" listens to its own
buttons, and works fine. The other two (F2 and F3) listen
to each other's buttons.
The "BUSY" button simply sets the cursor on its listener
to the busy cursor. The "DONE" button sets it to the
default cursor. These work fine.
The "SLEEP" button sets the cursor, sleeps for 3 seconds,
and sets it back. This does not work.
The "INVOKE LATER" button does the same thing,
except is uses invokeLater to sleep and set the
cursor back. This also does not work.
The "DELAY" button sleeps for 3 seconds (giving you
time to move the mouse into the other (listerner's)
window, and then it behaves just like the "SLEEP"
button. This works.
Any ideas would be appreciated, thanks.
-J
import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class BusyFrameTest implements ActionListener
private static Cursor busy = Cursor.getPredefinedCursor (Cursor.WAIT_CURSOR);
private static Cursor done = Cursor.getDefaultCursor();
JFrame frame;
JButton[] buttons;
public BusyFrameTest (String title)
frame = new JFrame (title);
buttons = new JButton[5];
buttons[0] = new JButton ("BUSY");
buttons[1] = new JButton ("DONE");
buttons[2] = new JButton ("SLEEP");
buttons[3] = new JButton ("INVOKE LATER");
buttons[4] = new JButton ("DELAY");
JPanel buttonPanel = new JPanel();
for (int i = 0; i < buttons.length; i++)
buttonPanel.add (buttons);
frame.getContentPane().add (buttonPanel);
frame.pack();
frame.setVisible (true);
public void addListeners (ActionListener listener)
for (int i = 0; i < buttons.length; i++)
buttons[i].addActionListener (listener);
public void actionPerformed (ActionEvent e)
System.out.print (frame.getTitle() + ": " + e.getActionCommand());
if (e.getActionCommand().equals ("BUSY"))
frame.setCursor (busy);
else if (e.getActionCommand().equals ("DONE"))
frame.setCursor (done);
else if (e.getActionCommand().equals ("SLEEP"))
frame.setCursor (busy);
try { Thread.sleep (3000); } catch (Exception ex) { }
frame.setCursor (done);
System.out.print (" finished");
else if (e.getActionCommand().equals ("INVOKE LATER"))
frame.setCursor (busy);
SwingUtilities.invokeLater (thread);
else if (e.getActionCommand().equals ("DELAY"))
try { Thread.sleep (3000); } catch (Exception ex) { }
frame.setCursor (busy);
try { Thread.sleep (3000); } catch (Exception ex) { }
frame.setCursor (done);
System.out.print (" finished");
System.out.println();
Runnable thread = new Runnable()
public void run()
try { Thread.sleep (3000); } catch (Exception ex) { }
frame.setCursor (done);
System.out.println (" finished");
public static void main (String[] args)
BusyFrameTest f1 = new BusyFrameTest ("F1");
f1.addListeners (f1);
BusyFrameTest f2 = new BusyFrameTest ("F2");
BusyFrameTest f3 = new BusyFrameTest ("F3");
f2.addListeners (f3); // 2 listens to 3
f3.addListeners (f2); // 3 listens to 2I've had the same problems with cursors and repaints in a swing application, and I was thinking of if I could use invokeLater, but I never got that far with it.
I still believe you would need a thread for the time consuming task, and that invokeLater is something you only need to use in a thread different from the event thread. -
We are experiencing a landry list of problems with java 1.2.2 and 1.3 when trying to print reasonably simple reports. I am just curious if anyone has encounterd problems like these, or if anyone has had any luck working around them. We would really like to release our software to production but I need to make sure that printing works well on all of the environments our client might run on. Here are the problems:
* Reporting was originaly done with a proprietary tool that limits us to using java.awt.PrintJob (new code is using PrinterJob... which is working okay...)
* When I try to use jre1.3 on my NT4.0 machine with a very simple program that gets a PrintJob it doesn't open the Print dialog and simply returns null (although it does work on my WinME laptop, and I cant find any bug reports about PrintJob dialogs on this site)
* When I try to use jre1.2 (which was our original target) there are problems with some printers running with some drivers (in house they are all various network HP printers). The printers will take 3 minutes a page while the same printer with an different driver (non-PS or PCL) will print very quickly.
Well I need some advice, are other people releasing software that doesn't work with all the possible ways that people could have their printers configured? Is there any hope of me finding a workaround... Is someone perhaps maintaining a list of drivers that work well with java? Or is there some empirical way of deciding (perhaps drivers that are not PS or PCL?)... Any responce would be very helpful...
--Erik HaddenWell, I decided to post my problem in more than one forum and got a response that may be what you are looking for. I haven't tried it yet and I'm not sure I understand it correctly, but I thought it may help you since it deals with printJob and supposedly works:
Other person wrote the following:
I have worked on printing but through Print Job.
i Print Multiple pages in landscsape.
in the printer Job you can print the static information
like if you implemented BOOk for mutiple pages it will only print the last information of your print function.
i found many problems when i was trying to implemnet printer Job
here is the complete code how can you print through print Job u can extends this to implement for multiple pages just use array of graphics.
Graphics Arrpage[];
Arrpage=new Graphics[count_pages];
PageAttributes pa=new PageAttributes();
pa.setOrientationRequested(PageAttributes.OrientationRequestedType.LANDSCAPE);
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
Toolkit toolkit = this.getToolkit();
PrintJob job = toolkit.getPrintJob(new Frame(), user,null,pa);
if (job == null) return;
for(int j=0;j<count_pages;j++)
Arrpage[j] = job.getGraphics();
// Check the size of the scribble component and of the page.
Dimension size = this.getSize();
Dimension pagesize = job.getPageDimension();
// Center the output on the page. Otherwise it would be
// be scrunched up in the upper-left corner of the page.
Arrpage[j].translate((pagesize.width - size.width)/2, (pagesize.height - size.height)/2);
Arrpage[j].setColor(Color.white);
Arrpage[j].fillRect(0,0,pagesize.width,pagesize.height);
Arrpage[j].setClip(0, 0, size.width, size.height);
Arrpage[j].dispose(); // End the page--send it to the printer.
//System.out.println("Disposing "+j+" page");
}// end of for loop
//System.out.println("before ending the job");
job.end(); // End the print job.
Hope this will help u. -
Problem with setOpaque() and transparency.
Hi,
I want to use the glass pane of my JFrame to indicate that my application is busy doing something. I want to make the JFrame go a "grey" color, have the busy cursor and be unresponsive to clicks until the task is finished.
I have included test code to show what I am trying to do. If you click on the "Start Busy" button, you will see what I am trying to achieve.
My problem is that when my glass pane is painting, I seem to get some underlying components painted in unusual positions. In this example, the "Start Busy" button gets drawn at the top left-hand corner of the JFrame when the glass pane is displayed.
H:\>java -version
java version "1.4.2_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04
Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;
public class Test {
public static void main(String args[]) {
final JFrame test = new JFrame("Transparency Test");
JPanel panel = new JPanel(new BorderLayout());
panel.add(new JLabel("NORTH", JLabel.CENTER), BorderLayout.NORTH);
panel.add(new JLabel("SOUTH", JLabel.CENTER), BorderLayout.SOUTH);
panel.add(new JLabel("EAST", JLabel.CENTER), BorderLayout.EAST);
panel.add(new JLabel("WEST", JLabel.CENTER), BorderLayout.WEST);
JPanel glassPanel = new JPanel();
glassPanel.setOpaque(true);
glassPanel.setBackground(new Color(200, 200, 200, 100));
glassPanel.setLayout(new GridBagLayout());
glassPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
JButton busyButton = new JButton("Start Busy");
busyButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Runnable busy = new Runnable() {
public void run() {
Component gp = test.getGlassPane();
gp.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
gp.setVisible(true);
gp.requestFocus();
try {
Thread.sleep(5000);
} catch (Throwable t) {
// Ignore...
gp.setVisible(false);
gp.setCursor(null);
Thread t = new Thread(busy);
t.start();
panel.add(busyButton, BorderLayout.CENTER);
test.setGlassPane(glassPanel);
test.getContentPane().add(panel);
test.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
test.pack();
test.show();
}You need to make the glass pane non-opaque so it will repaint the components underneath it. But when you do this the background doesn't get painted, so you need to create a custom component and paint the background yourself:
JComponent glassPane = new JComponent()
public void paintComponent(Graphics g)
g.setColor( getBackground() );
g.fillRect(0, 0, getSize().width, getSize().height);
glassPane.setOpaque( false );
glassPane.setBackground( new Color(240, 220, 220, 100) );
setGlassPane( glassPane ); -
HTML Link problem (Urgent!)
I'm writing a prrogram that displays an HTML file. I used a JEditorPane. I tryed using the hyperlinkListener but it doesn't work! here's the class I wrote...
can anyone help please?
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import browser.*;
import java.net.*;
import javax.swing.event.*;
* Classe :
* Description :
* Societe : Medias France
* @version 1.0
public class Aide extends JFrame implements HyperlinkListener
BrowserInterface bI;
URL url1;
static Interface parent;
public Aide(String titre, Interface i)
super(titre);
parent = i;
getContentPane().setLayout(new BorderLayout());
//bI = new BrowserInterface(jp);
setBounds(10,10,800,600);
addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
quit(null);
try
url1 = new URL("file:/home/darkazan/java/BDO/tablegen-1.8/help/help.html");
//bI.URL_Process(url1);
catch (MalformedURLException e)
System.out.println("probleme " + e.toString());
JEditorPane editorPane = new JEditorPane();
editorPane.setEditable(false);
try
editorPane.setPage(url1);
catch (IOException e)
System.err.println("Attempted to read a bad URL: " + url1);
JScrollPane editorScrollPane = new JScrollPane(editorPane);
editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
editorScrollPane.setPreferredSize(new Dimension(800, 600));
getContentPane().add(editorScrollPane, "Center");
pack();
setVisible(true);
public void hyperlinkListener(HyperlinkEvent e)
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
// do something on HL click
System.out.println("ouverture");
if (e.getEventType() == HyperlinkEvent.EventType.ENTERED)
// do something on mouse over HL
// do something on HL click
System.out.println("bbbbbbbbbbbbbbbbbbbb");
if (e.getEventType() == HyperlinkEvent.EventType.EXITED)
// do something on HL click
System.out.println("ggggggggggggggggggg");
// do something on mouse moved away from HL
public void hyperlinkUpdate(HyperlinkEvent e)
public static void main(String[] args)
Aide aide1 = new Aide("Help", parent);
* Quitter l'application
* @param e L'evenement recu
* @return Sans objet.
void quit(ActionEvent e)
parent.bAide.setEnabled(true);
dispose();
}also check your file protocol it should look like this: file:/// with three slashes(i think?)
here Mr. Urgent, my html viewer: (and it works) ;P
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.accessibility.*;
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import java.net.MalformedURLException;
import java.io.IOException;
public class iROCHelp extends JPanel implements HyperlinkListener{
//ATTRIBUTES
JEditorPane html;
private static boolean HelpShowing = false;
private static JFrame selTopic;
//METHODS
//Constructor
public iROCHelp(java.net.URL URLstr){
//setBorder(new EmptyBorder());
setLayout(new BorderLayout());
try{
URL url = URLstr;
if(url != null){
html = new JEditorPane(url);
html.setEditable(false);
html.addHyperlinkListener(this);
JScrollPane scroller = new JScrollPane();
JViewport vp = scroller.getViewport();
vp.add(html);
vp.setBackingStoreEnabled(true);
add(scroller, BorderLayout.CENTER);
catch (MalformedURLException e){
System.out.println("Malformed URL: " + e);
catch (IOException e){
System.out.println("IOException: " + e);
}//HelpTopic CONSTRUCTOR
public void hyperlinkUpdate(HyperlinkEvent e){
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED){
linkActivated(e.getURL());
}//hyperlinkUpdate
protected void linkActivated(URL u){
Cursor c = html.getCursor();
Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
html.setCursor(waitCursor);
SwingUtilities.invokeLater(new PageLoader(u, c));
}//linkActivated
class PageLoader implements Runnable{
PageLoader(URL u, Cursor c){
url = u;
cursor = c;
public void run(){
if (url == null){
// restore the original cursor
html.setCursor(cursor);
Container parent = html.getParent();
parent.repaint();
else{
Document doc = html.getDocument();
try{
html.setPage(url);
catch (IOException ioe){
html.setDocument(doc);
finally{
// schedule the cursor to revert after
// the paint has happended.
url = null;
SwingUtilities.invokeLater(this);
}//else
}//run
URL url;
Cursor cursor;
}//PageLoader
public static void spawnHelp(java.net.URL URLStr){
if (!HelpShowing){
selTopic = new JFrame();
selTopic.getContentPane().setLayout(new BorderLayout());
selTopic.getContentPane().add(new iROCHelp(URLStr),BorderLayout.CENTER);
Dimension dim = selTopic.getToolkit().getScreenSize();
selTopic.setLocation((int)dim.getWidth()/2-selTopic.getWidth()/2,(int)dim.getHeight()/2-selTopic.getHeight()/2);
selTopic.setSize(500, 400);
selTopic.setTitle("Remote Operators Console Help");
selTopic.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
closeHelp();
}//windowClosing
selTopic.show();
HelpShowing = true;
}//if help showing
}//spawnHelp
public static void closeHelp(){
if (HelpShowing){
selTopic.dispose();
HelpShowing = false;
}//closeHelp
}//HelpTopic CLASS -
Attachment Problem in JavaMail API
Can anybody help me...
when 'm trying to attach a file to a mailing aplication(sending attachment),
an flurry of exceptions are occuring...
'm using win98 and JDK1.4
here is the code..can anybody provide a viable solution that works?
thanks in advance
* main1.java
* Created on August 20, 2002, 2:55 PM
* @author Shamik Ghosh
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.net.*;
import java.io.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class main1 extends javax.swing.JFrame implements ActionListener,ItemListener {
JMenuBar mbar;
JMenu file,other,help;
JMenuItem open,save,read_mail;
JFrame frame_f;
FileReader fr;
BufferedReader br;
boolean check;
String from_m,smtp_m,from_m1,smtp_m1,result,
s1,s2,from_server,from_host,to_file,which_file,attach_text;
File f;
/** Creates new form main1 */
public main1() {
initComponents();
setSize(550,500);
setResizable(false);
// ------------------------centering the display
int width=550; // note that "width" & "height" are keywords and
int height=500; // JAVA defined variables.
Dimension screen=Toolkit.getDefaultToolkit().getScreenSize();
int x=(screen.width-width)/2;
int y=(screen.height-height)/2;
setBounds(x,y,width,height);
try{
fr=new FileReader("address.txt");
br=new BufferedReader(fr);
String s;
while((s=br.readLine()) !=null)
{jComboBox1.addItem(s);}
fr.close();
}catch(Exception e){ System.out.println(e);}
check_info();//calling the method to check the info
//jTextField1.setText(from_m);
//jTextField3.setText(smtp_m);
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
private void initComponents() {//GEN-BEGIN:initComponents
buttonGroup1 = new javax.swing.ButtonGroup();
buttonGroup2 = new javax.swing.ButtonGroup();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jTextField3 = new javax.swing.JTextField();
jComboBox1 = new javax.swing.JComboBox();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
jRadioButton3 = new javax.swing.JRadioButton();
jRadioButton4 = new javax.swing.JRadioButton();
jButton4 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jTextField4 = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jScrollPane2 = new javax.swing.JScrollPane();
jTextArea2 = new javax.swing.JTextArea();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
//actionlisteners
jButton1.addActionListener(this);
jButton2.addActionListener(this);
jButton3.addActionListener(this);
jButton4.addActionListener(this);
jButton5.addActionListener(this);
jButton6.addActionListener(this);
mbar=new JMenuBar();
setJMenuBar(mbar);
file=new JMenu("File");
other=new JMenu("Other");
help=new JMenu("Help");
mbar.add(file);
mbar.add(other);
mbar.add(help);
getContentPane().setLayout(null);
setTitle("MailMan :Designed and Programmed by Shamik Ghosh");
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
jLabel1.setText("From:");
getContentPane().add(jLabel1);
jLabel1.setBounds(30, 20, 32, 17);
jLabel2.setText("To:");
getContentPane().add(jLabel2);
jLabel2.setBounds(30, 60, 17, 17);
getContentPane().add(jTextField1);
jTextField1.setBounds(110, 20, 240, 21);
getContentPane().add(jTextField2);
jTextField2.setBounds(110, 60, 240, 21);
jLabel3.setText("Smtp Server:");
getContentPane().add(jLabel3);
jLabel3.setBounds(10, 100, 74, 17);
getContentPane().add(jTextField3);
jTextField3.setBounds(110, 100, 240, 21);
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { }));
jComboBox1.setToolTipText("Mail Addresses");
jComboBox1.setAutoscrolls(true);
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jComboBox1ActionPerformed(evt);
getContentPane().add(jComboBox1);
jComboBox1.setBounds(110, 150, 240, 20);
jComboBox1.setFont(new java.awt.Font("Abadi MT Condensed Light", 1, 12));
jButton1.setToolTipText("Send the message you have typed");
jButton1.setMnemonic('m');
jButton1.setFont(new java.awt.Font("Abadi MT Condensed Light", 1, 12));
jButton1.setText("Send Mail");
getContentPane().add(jButton1);
jButton1.setBounds(370, 300, 160, 25);
//jButton2.setFont(new java.awt.Font("Abadi MT Condensed Light", 0, 12));
jButton2.setText("Save Info");
jButton2.setToolTipText("Save Settings for more mails");
jButton2.setMnemonic('I');
getContentPane().add(jButton2);
jButton2.setBounds(370, 340, 160, 25);
jButton3.setText("Clear ");
jButton3.setMnemonic('C');
jButton3.setToolTipText("Clear all text");
getContentPane().add(jButton3);
jButton3.setBounds(370, 380, 160, 27);
jLabel4.setText("Your Contact Addresses");
jLabel4.setFont(new java.awt.Font("Arial Narrow", 0, 12));
getContentPane().add(jLabel4);
jLabel4.setBounds(110, 130, 200, 15);
jRadioButton3.setText("Use Log File");
jRadioButton3.setMnemonic('L');
getContentPane().add(jRadioButton3);
jRadioButton3.setBounds(260, 310, 90, 25);
jRadioButton4.setText("No Log File");
//jRadioButton4.setMnemonic('N');
//getContentPane().add(jRadioButton4);
//jRadioButton4.setBounds(260, 340, 86, 25);
jButton4.setText("Undo Info");
jButton4.setMnemonic('U');
jButton4.setToolTipText("Undo settings");
getContentPane().add(jButton4);
jButton4.setBounds(260, 380, 87, 27);
getContentPane().add(jTextField4);
jTextField4.setBounds(20, 380, 210, 21);
jLabel5.setText("Attachment");
jLabel5.setFont(new java.awt.Font("Abadi MT Condensed Light", 1, 12));
getContentPane().add(jLabel5);
jLabel5.setBounds(70, 360, 70, 15);
jButton5.setFont(new java.awt.Font("Abadi MT Condensed Light", 1, 12));
jButton5.setText("Browse");
jButton5.setMnemonic('B');
jButton5.setToolTipText("Browse files for Attachment");
getContentPane().add(jButton5);
jButton5.setBounds(150, 350, 80, 25);
jButton6.setText("Attach & Send");
jButton6.setMnemonic('A');
jButton6.setToolTipText("Attach File & Send Mail");
getContentPane().add(jButton6);
jButton6.setBounds(260, 340, 86, 25);
jScrollPane1.setViewportView(jTextArea1);
getContentPane().add(jScrollPane1);
jScrollPane1.setBounds(370, 20, 160, 270);
jLabel10.setText("Type your mail:");
jLabel10.setFont(new java.awt.Font("Abadi MT Condensed Light", 1, 12));
getContentPane().add(jLabel10);
jLabel10.setBounds(370, 5, 125, 10);
jScrollPane2.setViewportView(jTextArea2);
getContentPane().add(jScrollPane2);
jScrollPane2.setBounds(20, 200, 340, 90);
jLabel6.setText("(your ISP smtp)");
jLabel6.setFont(new java.awt.Font("Abadi MT Condensed Light", 0, 10));
getContentPane().add(jLabel6);
jLabel6.setBounds(10, 120, 70, 12);
jLabel7.setText("porgrammed and designed by : Shamik Ghosh");
jLabel7.setFont(new java.awt.Font("Abadi MT Condensed Light", 0, 10));
getContentPane().add(jLabel7);
jLabel7.setBounds(260, 410, 160, 12);
jLabel8.setText("[email protected]");
jLabel8.setFont(new java.awt.Font("Abadi MT Condensed Light", 0, 10));
getContentPane().add(jLabel8);
jLabel8.setBounds(420, 410, 80, 12);
jLabel9.setText("Msg.for the Mail Sent:");
jLabel9.setForeground(java.awt.Color.black);
jLabel9.setFont(new java.awt.Font("Abadi MT Condensed Light", 0, 10));
getContentPane().add(jLabel9);
jLabel9.setBounds(20, 180, 80, 12);
file.add(open=new JMenuItem("Open"));
open.setAccelerator(KeyStroke.getKeyStroke('O',Event.CTRL_MASK,true));
file.addSeparator();
file.add(save=new JMenuItem("Save"));
save.setAccelerator(KeyStroke.getKeyStroke('S',Event.CTRL_MASK,true));
file.addSeparator();
other.add(read_mail=new JMenuItem("Add Address"));
read_mail.setAccelerator(KeyStroke.getKeyStroke('A',Event.CTRL_MASK,true));
other.addSeparator();
//adding actionListener to menuitems
open.addActionListener(this);
save.addActionListener(this);
read_mail.addActionListener(this);
jComboBox1.addItemListener(this);
pack();
}//GEN-END:initComponents
public void itemStateChanged(ItemEvent ie)
String add_list;
add_list=String.valueOf(jComboBox1.getSelectedItem());
jTextField2.setText(add_list);
} // for item event source
public void actionPerformed(ActionEvent ae)
if(ae.getSource()==jButton1)
if(ae.getSource()==jButton1) {
SwingUtilities.invokeLater(new Runnable()
{ public void run()
sendMail();
if(ae.getSource()==jButton2) //save info
from_m =jTextField1.getText();
smtp_m =jTextField3.getText();
from_m1 =from_m+"\n";
smtp_m1 =jTextField3.getText();
result =from_m1+smtp_m1;
try{
byte buf[]=result.getBytes();
OutputStream fo=new FileOutputStream("info.txt");
for(int i=0;i<buf.length; i++ )
fo.write(buf);
fo.close();
}catch(Exception e){ System.out.println(e);}
jTextField1.setEditable(false);
jTextField3.setEditable(false);
if(ae.getSource()==jButton3) //clear
jTextArea1.setText(" ");
jTextArea2.setText(" ");
if(ae.getSource()==jButton4)//undo info
jTextField1.setEditable(true);
jTextField3.setEditable(true);
if(ae.getSource()==jButton5)//browse for attachment
try {
FileDialog file = new FileDialog (main1.this, "Load File", FileDialog.LOAD);
file.setFile ("*.*"); // Set initial filename filter
file.show(); // Blocks
String curFile;
if ((curFile = file.getFile()) != null) {
String filename = file.getDirectory() + curFile;
char[] data;
setCursor (Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
f = new File (filename);
try {
System.out.println("INSIDE TRY");
FileReader fin = new FileReader (f);
int filesize = (int)f.length();
data = new char[filesize];
fin.read (data, 0, filesize);
setCursor (Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
} catch (Exception exc) {}
jTextField4.setText(filename);
} catch(Exception e){}
if(ae.getSource()==jButton6)//send attachment & Mail
try{
sendmail2();
}catch(Exception e){}
if(ae.getSource()==open)//menu open
if(ae.getSource()==save)//menu save
if(ae.getSource()==read_mail)//menu read_mail
address_add();
} //actionperformed
public void sendmail2()
try {
//which_file,attach_text
from_server=jTextField3.getText();
from_host=jTextField1.getText();
to_file=jTextField2.getText();
which_file=jTextField4.getText();
attach_text=jTextArea1.getText();
//getting system property
Properties props=System.getProperties();
//setup mail server
props.put("mail.smtp.host",from_server);
//get session
Session session=Session.getInstance(props,null);
// Define message
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from_host));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to_file));
message.setSubject("Hello JavaMail Attachment");
//define message part
BodyPart messageBodyPart=new MimeBodyPart();
// Fill the message
messageBodyPart.setText(attach_text);
// Create a Multipart
Multipart multipart = new MimeMultipart();
// Add part one
multipart.addBodyPart(messageBodyPart);
//attaching**********************************secon Part Attachment
//creating second body part
messageBodyPart=new MimeBodyPart();
DataSource source=new FileDataSource(which_file); //was filename
//setting data handler to the attachment
messageBodyPart.setDataHandler(new DataHandler(source));
//setting the filename
messageBodyPart.setFileName(which_file);
//adding part two
multipart.addBodyPart(messageBodyPart);
//put parts in the message
message.setContent(multipart);
//Sending msg
Transport.send(message);
}catch(Exception e){}
} //sendmail2
public void address_add()
addr=jTextField2.getText();
str_addr=addr+"\n";
//jComboBox1.addItem(" ");
jComboBox1.addItem(addr);
System.out.println("INSIDE WRITING METHOD");
try{
byte buf[]=str_addr.getBytes();
OutputStream f0=new FileOutputStream("address.txt",true);
for(int i=0;i<buf.length; i++ )
f0.write(buf[i]);
f0.close();
}catch(Exception e){ System.out.println(e);}
public void check_info()
try{
fr=new FileReader("info.txt");
br=new BufferedReader(fr);
while((s1=br.readLine()) !=null && (s2=br.readLine()) !=null)
jTextField1.setText(s1);
jTextField3.setText(s2);
break;
fr.close();
}catch(Exception e){ System.out.println(e);}
public void sendMail()
{ try
Socket s = new Socket(jTextField3.getText(), 25);
out = new PrintWriter(s.getOutputStream());
in = new BufferedReader(new
InputStreamReader(s.getInputStream()));
String hostName
= InetAddress.getLocalHost().getHostName();
send(null);
send("Host " + hostName);
send("Mail FROM: " + jTextField1.getText());
send("Rcpt TO: " + jTextField2.getText());
send("Data");
out.println(jTextArea1.getText());
send(".");
s.close();
catch (IOException exception)
{ jTextArea2.append("Error: " + exception);
String err="Message cannot be sent!"+"\n"
+"Please verify the setting(s)."+
"\n"+"Else there may be a NetWork Problem."+
"\n"+"Please verify and Try Again.";
JOptionPane.showMessageDialog(frame_f,err,"Message Transmission Failure",JOptionPane.ERROR_MESSAGE);
public void send(String s) throws IOException
{ if (s != null)
{ jTextArea2.append(s + "\n");
out.println(s);
out.flush();
String line;
if ((line = in.readLine()) != null)
jTextArea2.append(line + "\n");
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
// Add your handling code here:
}//GEN-LAST:event_jComboBox1ActionPerformed
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
System.exit(0);
}//GEN-LAST:event_exitForm
* @param args the command line arguments
public static void main(String args[]) {
new main1().show();
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.ButtonGroup buttonGroup2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JLabel jLabel3;
private javax.swing.JTextField jTextField3;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel4;
private javax.swing.JRadioButton jRadioButton3;
private javax.swing.JRadioButton jRadioButton4;
private javax.swing.JButton jButton4;
private javax.swing.JTextField jTextField4;
private javax.swing.JLabel jLabel5;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextArea jTextArea2;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JLabel jLabel10;
private BufferedReader in;
private PrintWriter out;
private String addr,str_addr;
// End of variables declaration//GEN-END:variablesHi I have this problem which I believe you can help me resolve:
In my code, there are two lines:
message.setContent(messageBody, "text/html"); // this sets body of message
message.setContent(bodyPartObject); // this attaches a file
but it turns out that the second "setContent" statement over-writes the first one, so that I get no message in the body of the mail.
What can I do about it, shamik1? Thanks! -
Problem in display file in java applet embeded browser
hi, i am facing problem to display the file from local drive in java applet embeded browser. here is the error message i get:
Exception loading file from path:java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
i think it should be the java security problem and i have try to get the solution from internet. i try to solve by using the fllowing method:
keytool -genkey -keyalg rsa -alias yourkey
keytool -export -alias yourkey -file yourcert.crt
javac yourapplet.java
jar cvf yourapplet.jar yourapplet.class
jarsigner yourapplet.jar yourkey
but the command prompt ask me to enter the keystore password. i try to enter any password. but i show me the error:
keytool error: java.io.IOException: Keystore was tampered with, or password was incorrect.
So may i know what is the problem actually?Thanks a lot.Hi,
here is the sample coding :
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
import com.sun.j3d.utils.behaviors.mouse.MouseZoom;
import com.sun.j3d.utils.behaviors.mouse.MouseTranslate;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.net.URL;
import java.net.MalformedURLException;
import org.web3d.j3d.loaders.VRML97Loader;
import com.sun.j3d.loaders.Scene;
public class SimpleVrml extends Applet implements ActionListener {
String location;
String initLocation;
Canvas3D canvas;
SimpleUniverse universe;
TransformGroup vpTransGroup;
VRML97Loader loader;
View view;
Panel panel;
Label label;
BranchGroup sceneRoot;
TransformGroup examineGroup;
BranchGroup sceneGroup;
BoundingSphere sceneBounds;
DirectionalLight headLight;
AmbientLight ambLight;
TextField textField;
Cursor waitCursor;
Cursor handCursor;
public SimpleVrml() {
initLocation="cylinder.wrl";
setLayout(new BorderLayout());
GraphicsConfiguration config =SimpleUniverse.getPreferredConfiguration();
setLayout(new BorderLayout());
canvas = new Canvas3D(config);
add("Center",canvas);
panel = new Panel();
panel.setLayout(new FlowLayout(FlowLayout.LEFT));
textField = new TextField(initLocation,60);
textField.addActionListener(this);
label = new Label("Location:");
panel.add(label);
panel.add(textField);
add("North",panel);
waitCursor = new Cursor(Cursor.WAIT_CURSOR);
handCursor = new Cursor(Cursor.HAND_CURSOR);
universe = new SimpleUniverse(canvas);
ViewingPlatform viewingPlatform = universe.getViewingPlatform();
vpTransGroup = viewingPlatform.getViewPlatformTransform();
Viewer viewer = universe.getViewer();
view = viewer.getView();
setupBehavior();
loader = new VRML97Loader();
gotoLocation(initLocation);
public void actionPerformed(ActionEvent ae) {
gotoLocation(textField.getText());
void gotoLocation(String location) {
canvas.setCursor(waitCursor);
if (sceneGroup != null) {
sceneGroup.detach();
Scene scene = null;
try {
URL loadUrl = new URL(location);
try {
// load the scene
scene = loader.load(new URL(location));
} catch (Exception e) {
System.out.println("Exception loading URL:" + e);
} catch (MalformedURLException badUrl) {
// location may be a path name
try {
// load the scene
scene = loader.load(location);
} catch (Exception e) {
System.out.println("Exception loading file from path:" + e);
if (scene != null) {
// get the scene group
sceneGroup = scene.getSceneGroup();
sceneGroup.setCapability(BranchGroup.ALLOW_DETACH);
sceneGroup.setCapability(BranchGroup.ALLOW_BOUNDS_READ);
// add the scene group to the scene
examineGroup.addChild(sceneGroup);
// now that the scene group is "live" we can inquire the bounds
sceneBounds = (BoundingSphere)sceneGroup.getBounds();
// set up a viewpoint to include the bounds
setViewpoint();
canvas.setCursor(handCursor);
void setViewpoint() {
Transform3D viewTrans = new Transform3D();
Transform3D eyeTrans = new Transform3D();
// point the view at the center of the object
Point3d center = new Point3d();
sceneBounds.getCenter(center);
double radius = sceneBounds.getRadius();
Vector3d temp = new Vector3d(center);
viewTrans.set(temp);
// pull the eye back far enough to see the whole object
double eyeDist = 1.4*radius / Math.tan(view.getFieldOfView() / 2.0);
temp.x = 0.0;
temp.y = 0.0;
temp.z = eyeDist;
eyeTrans.set(temp);
viewTrans.mul(eyeTrans);
// set the view transform
vpTransGroup.setTransform(viewTrans);
private void setupBehavior() {
sceneRoot = new BranchGroup();
examineGroup = new TransformGroup();
examineGroup.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
examineGroup.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
examineGroup.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
examineGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
examineGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
sceneRoot.addChild(examineGroup);
BoundingSphere behaviorBounds = new BoundingSphere(new Point3d(),
Double.MAX_VALUE);
MouseRotate mr = new MouseRotate();
mr.setTransformGroup(examineGroup);
mr.setSchedulingBounds(behaviorBounds);
sceneRoot.addChild(mr);
MouseTranslate mt = new MouseTranslate();
mt.setTransformGroup(examineGroup);
mt.setSchedulingBounds(behaviorBounds);
sceneRoot.addChild(mt);
MouseZoom mz = new MouseZoom();
mz.setTransformGroup(examineGroup);
mz.setSchedulingBounds(behaviorBounds);
sceneRoot.addChild(mz);
BoundingSphere lightBounds =
new BoundingSphere(new Point3d(), Double.MAX_VALUE);
ambLight = new AmbientLight(true, new Color3f(1.0f, 1.0f, 1.0f));
ambLight.setInfluencingBounds(lightBounds);
ambLight.setCapability(Light.ALLOW_STATE_WRITE);
sceneRoot.addChild(ambLight);
headLight = new DirectionalLight();
headLight.setCapability(Light.ALLOW_STATE_WRITE);
headLight.setInfluencingBounds(lightBounds);
sceneRoot.addChild(headLight);
universe.addBranchGraph(sceneRoot);
public static void main(String[] args) {
new MainFrame(new SimpleVrml(), 780, 780);
cylinder.wrl :
#VRML V2.0 utf8
# A cylinder
Shape {
appearance Appearance {
material Material { }
geometry Cylinder {
height 2.0
radius 1.5
view.html:
<html>
<applet code="SimpleVrml.class" width=600 height=600>
</applet>
</html>
error msg that i get :
Exception loading file from path:java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
i can display the wrl file in applet itself but i can't display in the browser.is it any problem with my code?Urgent, please help me. Thanks.
Maybe you are looking for
-
MIRO - display field ID and text
Hello all - I know this is simple. I just cannot remember where it is. When I am in MIRO, I see the tax code and tax description. For the plant, all I see is the plant code. Where/how can I set it to see both the plant code and the plant descrip
-
my location services r not working
-
Uh Oh, HD problems and I have pics to process..HELP
Since my Mac puts itself to sleep at night I was advised to run MacJanitor every morning, but ever since I've been doing this I've had some problems. Not sure if there's a connection, but it seems like my Mac was happier when I just left it alone. Pr
-
I' ve got the following runtime error on a JSP-based application: Konvertierung zwischen UTF8 und UCS2 nicht erfolgreich: failUTF8Conv (conversion between UTF8 and UCS2 not successfull: failUTF8Conv) I use the jdbc:thin driver for Release 9.2.0.1 The
-
Hi Forgive me if this has been covered to death - I'm relatively new to this and can't solve this problem. Would anybody be so kind as to look at my preloader and tell me how to rectify it. The revolving coloured circle starts as an elipse all bunche