[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

03/11/2009 at 11:49AM PDT, ID: 24221125
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.6

Applet not displayed in browser

Asked by akah123 in Java Programming Language, WebApplications, Apache Web Server

Tags: applet browser signed packages display error java

Basically I had a problem with a applet not being able to be viewed whilst in apache tomcat. It was able to be viewed locally. A link to to my old question: http://www.experts-exchange.com/Programming/Languages/Java/Q_24189477.html

I have made some changes to my original code from the previous question. The GUI has been modified slightly. The read in a file and display it in a message dialog box. The CODE WORKS FINE when it is an application. But I need it as an applet and am unable to get it to work. A similar error message to the one I had before is displayed.

My ultimate goal is to have a signed applet that can work from the apache tomcat server.

So the main problem is that nothing but a grey box is displayed when I attempt to run the applet. A error message is present in the blank screen.

My app is a simple browser that will display webpages that is run as a applet. Previously it worked but could not be loaded by tomcat, however since my changes I am unable to even run it locally. So I think it must be an issue with the code.

The java file along along with the html is located in the directory: C:\base_1\com_1\test_1

I think possibly a problem with the GUI is the most probable.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
<HTML>
<Head>
<Title> A Simple Program </Title>
<Body>
 
<Applet
 
Code="com_1.test_1.Mini_Applet_Browser_1"
 
width="800" height="850">
</Applet>
 
</Body>
</HTML>
 
package com_1.test_1;
import java.applet.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.html.*;
import java.util.StringTokenizer;
 
public class Mini_Applet_Browser_1 extends Applet implements HyperlinkListener {
	    // These are the buttons for iterating through the page list.
	    private JButton backButton, forwardButton,  test, viewDomains;
		
		JPanel mainPanel;
	    
	    // Page location text field.
	    private JTextField locationTextField;
	    
	    // Editor pane for displaying pages.
	    private JEditorPane displayEditorPane;
	    
	    // Browser's list of pages that have been visited.
	    private ArrayList pageList = new ArrayList();
		
		//Holds domains from file
		private ArrayList<String> domainList = new ArrayList<String>();
	    
	    // Constructor for Mini Web Browser.
	    public void init() {
	        // Set application title.
	        //super("Mini Browser");
	        
	        // Set window size.
	        setSize(640, 480);
	        
	        /** Handle closing events.
	        addWindowListener(new WindowAdapter() {
	            public void windowClosing(WindowEvent e) {
	                actionExit();
	            }
	        }  };
	        **/
	  
	        
	        
	        // Set up file menu.
	        JMenuBar menuBar = new JMenuBar();
	        JMenu fileMenu = new JMenu("File");
	        fileMenu.setMnemonic(KeyEvent.VK_F);
	        JMenuItem fileExitMenuItem = new JMenuItem("Exit",
	                KeyEvent.VK_X);
	        fileExitMenuItem.addActionListener(new ActionListener() {
	            public void actionPerformed(ActionEvent e) {
	                actionExit();
	            }
	        });
	        fileMenu.add(fileExitMenuItem);
	        menuBar.add(fileMenu);
	        //setJMenuBar(menuBar);
	        this.add(menuBar);
	        
	        // Set up button panel.
	        JPanel buttonPanel = new JPanel();
	        backButton = new JButton("< Back");
	        backButton.addActionListener(new ActionListener() {
	            public void actionPerformed(ActionEvent e) {
	                actionBack();
	            }
	        });
	        backButton.setEnabled(false);
	        buttonPanel.add(backButton);
	        forwardButton = new JButton("Forward >");
	        forwardButton.addActionListener(new ActionListener() {
	            public void actionPerformed(ActionEvent e) {
	                actionForward();
	            }
	        });
	        forwardButton.setEnabled(false);
	        buttonPanel.add(forwardButton);
	        locationTextField = new JTextField(35);
	        locationTextField.addKeyListener(new KeyAdapter() {
	            public void keyReleased(KeyEvent e) {
	                if (e.getKeyCode() == KeyEvent.VK_ENTER) {
	                    actionGo();
	                }
	            }
	        });
	        buttonPanel.add(locationTextField);
	        JButton goButton = new JButton("GO");
	        goButton.addActionListener(new ActionListener() {
	            public void actionPerformed(ActionEvent e) {
	                actionGo();
	            }
	        });
	        buttonPanel.add(goButton);
			
			//test button and actionlistner. 
        JButton test = new JButton("Test");
        test.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	restrictURL();
            }
        });
        buttonPanel.add(test);
		
		 //domain button to view available one's and actionlistner. 
        JButton viewDomains = new JButton("Available domains");
        viewDomains.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                alertDomains();
            }
        });
        buttonPanel.add(viewDomains);
	        
	        // Set up page display.
	        displayEditorPane = new JEditorPane();
	        displayEditorPane.setContentType("text/html");
	        displayEditorPane.setEditable(false);
	        displayEditorPane.addHyperlinkListener(this);
	        /**
	        getContentPane().setLayout(new BorderLayout());
	        getContentPane().add(buttonPanel, BorderLayout.NORTH);
	        getContentPane().add(new JScrollPane(displayEditorPane),
	                BorderLayout.CENTER);
	    }
	    **/
	        this.setLayout(new BorderLayout());
	        this.add(buttonPanel, BorderLayout.NORTH);
	        this.add(new JScrollPane(displayEditorPane),
	                BorderLayout.CENTER);
	    }
	        
	    // Exit this program.
	    private void actionExit() {
	        System.exit(0);
	    }
	    
	    // Go back to the page viewed before the current page.
	    private void actionBack() {
	        URL currentUrl = displayEditorPane.getPage();
	        int pageIndex = pageList.indexOf(currentUrl.toString());
	        try {
	            showPage(
	                    new URL((String) pageList.get(pageIndex - 1)), false);
	        } catch (Exception e) {}
	    }
	    
	    // Go forward to the page viewed after the current page.
	    private void actionForward() {
	        URL currentUrl = displayEditorPane.getPage();
	        int pageIndex = pageList.indexOf(currentUrl.toString());
	        try {
	            showPage(
	                    new URL((String) pageList.get(pageIndex + 1)), false);
	        } catch (Exception e) {}
	    }
	    
	    // Load and show the page specified in the location text field.
	    private void actionGo() {
	        URL verifiedUrl = verifyUrl(locationTextField.getText());
	        if (verifiedUrl != null) {
	            showPage(verifiedUrl, true);
	        } else {
	            showError("Invalid URL");
	        }
	    }
	    
	    // Show dialog box with error message.
	    private void showError(String errorMessage) {
	        JOptionPane.showMessageDialog(this, errorMessage,
	                "Error", JOptionPane.ERROR_MESSAGE);
	    }
	    
	    // Verify URL format.
	    private URL verifyUrl(String url) {
	        // Only allow HTTP URLs.
	        if (!url.toLowerCase().startsWith("http://"))
	            return null;
	        
	        // Verify format of URL.
	        URL verifiedUrl = null;
	        try {
	            verifiedUrl = new URL(url);
	        } catch (Exception e) {
	            return null;
	        }
	        
	        return verifiedUrl;
	    }
	    
	  /* Show the specified page and add it to
	     the page list if specified. */
	    private void showPage(URL pageUrl, boolean addToList) {
	        // Show hour glass cursor while crawling is under way.
	        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
	        
	        try {
	            // Get URL of page currently being displayed.
	            URL currentUrl = displayEditorPane.getPage();
	            
	            // Load and display specified page.
	            displayEditorPane.setPage(pageUrl);
	            
	            // Get URL of new page being displayed.
	            URL newUrl = displayEditorPane.getPage();
	            
	            // Add page to list if specified.
	            if (addToList) {
	                int listSize = pageList.size();
	                if (listSize > 0) {
	                    int pageIndex =
	                            pageList.indexOf(currentUrl.toString());
	                    if (pageIndex < listSize - 1) {
	                        for (int i = listSize - 1; i > pageIndex; i--) {
	                            pageList.remove(i);
	                        }
	                    }
	                }
	                pageList.add(newUrl.toString());
	            }
	            
	            // Update location text field with URL of current page.
	            locationTextField.setText(newUrl.toString());
	            
	            // Update buttons based on the page being displayed.
	            updateButtons();
	        } catch (Exception e) {
	            // Show error messsage.
	            showError("Unable to load page");
	        } finally {
	            // Return to default cursor.
	            setCursor(Cursor.getDefaultCursor());
	        }
	    }
	    
	  /* Update back and forward buttons based on
	     the page being displayed. */
	    private void updateButtons() {
	        if (pageList.size() < 2) {
	            backButton.setEnabled(false);
	            forwardButton.setEnabled(false);
	        } else {
	            URL currentUrl = displayEditorPane.getPage();
	            int pageIndex = pageList.indexOf(currentUrl.toString());
	            backButton.setEnabled(pageIndex > 0);
	            forwardButton.setEnabled(
	                    pageIndex < (pageList.size() - 1));
	        }
	    }
	    
	    // Handle hyperlink's being clicked.
	    public void hyperlinkUpdate(HyperlinkEvent event) {
	        HyperlinkEvent.EventType eventType = event.getEventType();
	        if (eventType == HyperlinkEvent.EventType.ACTIVATED) {
	            if (event instanceof HTMLFrameHyperlinkEvent) {
	                HTMLFrameHyperlinkEvent linkEvent =
	                        (HTMLFrameHyperlinkEvent) event;
	                HTMLDocument document =
	                        (HTMLDocument) displayEditorPane.getDocument();
	                document.processHTMLFrameHyperlinkEvent(linkEvent);
	            } else {
	                showPage(event.getURL(), true);
	            }
	        }
	    }
		
		
		public void alertDomains(){
    	try
        {
                Scanner scan = new Scanner(new File("C:/Users/Anthony/url/urlFile.txt"));
                domainList.clear();
 
                while(scan.hasNextLine())
                {
                        String[] parts = scan.nextLine().split(".\\) "); //Split the line based on the regular expression.
                        // the "." means any character and is used to represent the number.
                        // the "\\)" means the character ")" and since it is an unusual character it must be preceded by the "\\" in the expression.
 
                        for(String s : parts)//Go through each string on this line
                                if(s.length() != 0)//Only add the string if it is not blank
                                        domainList.add(s);
 
                        domainList.add("\n");//Adds a new line after each line;
                        // "\n" represents a line break
                }
    }
        catch (IOException ec)
        {
                ec.printStackTrace();
    }
        
        //adding elements
        String z = ""; //empty string to store domainList elements
   	 
        for(String a: domainList)
                z += "-"+a; //should keep adding each element to string z.
 
        JOptionPane.showMessageDialog(null,z);//should display
 
    }
    
    //Get the url textfield
    public String getUrlField(){
		return locationTextField.getText();
	}
    
    public void restrictURL(){
    	String url = getUrlField();//get url field
    	
    	for (String avDoms: domainList){//iterate through arraylist that contains url's
    		//url matches arraylist element
    		
    		if (url.equals(avDoms)){
    			
    			actionGo();
    			JOptionPane.showMessageDialog(null,"This URL works!");
    		}
    		else{
    			JOptionPane.showMessageDialog(null,"Sorry you can not access this webpage!",
    					"Access denied", JOptionPane.ERROR_MESSAGE);//should an message denying access
    		}
    		
    	    		
    		
    	}//end of for
    	
    }//end of method	
    	
	    
	   
 
}
[+][-]03/11/09 11:51 AM, ID: 23860848

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/11/09 11:59 AM, ID: 23860921

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/11/09 12:02 PM, ID: 23860962

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/11/09 12:09 PM, ID: 23861037

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/11/09 12:15 PM, ID: 23861117

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/11/09 12:20 PM, ID: 23861173

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/11/09 12:27 PM, ID: 23861246

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/11/09 12:36 PM, ID: 23861370

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/11/09 12:41 PM, ID: 23861441

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Java Programming Language, WebApplications, Apache Web Server
Tags: applet browser signed packages display error java
Sign Up Now!
Solution Provided By: CEHJ
Participating Experts: 1
Solution Grade: A
 
 
[+][-]03/11/09 12:53 PM, ID: 23861595

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/11/09 12:57 PM, ID: 23861652

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/11/09 02:23 PM, ID: 23862541

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/11/09 02:29 PM, ID: 23862592

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/11/09 03:18 PM, ID: 23862951

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20090824-EE-VQP-74 - Hierarchy / EE_QW_3_20080625