Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can you please fix the error. package com.IST240Apps; import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*; import java.net.*; public class LinkRotator extends JFrame implements Runnable,
Can you please fix the error.
package com.IST240Apps;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import java.net.*;
public class LinkRotator extends JFrame
implements Runnable, ActionListener {
String[] pageTitle = new String[5];
URI[] pageLink = new URI[5];
int current = 0;
Thread runner;
JLabel siteLabel = new Jlabel();
public LinkRotator() {
setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
setSize(300, 100);
FlowLayout flo = new Flowlayout();
setLayout(flo);
add(siteLabel);
pageTitle = new String[] {
"Oracle Java Site",
"Server Side",
"JavaWorld",
"Google",
"Yahoo",
"Penn State"
};
pageLink[0] = getUR1("http://www.oracle.com/technetwork/java");
pageLink[1] = getUR1("http://www.theserverside.com");
pageLink[2] = getUR1("http://www.javaworld.com");
pageLink[3] = getUR1("http://www.google.com");
pageLink[4] = getUR1("http://yahoo.com");
pageLink[5] = getUR1("http://www.psu.edu");
Button visitButton = new Button("Visit Site");
visitButton.addActionListener(this);
add(visitButton);
setVisible(true);
start();
}
private URI getURI(String urlText) {
URI pageUR1 = null;
try {
pageURI = new URI(urlText);
} catch (URISyntaxException ex) {
// do nothing
}
return pageURI;
}
public void start() {
if (runner = null) {
runner = new Thread(this);
runner.start();
}
}
public void run() {
Thread thisThread = Thread.currentThread();
while (runner = thisThread) {
current++;
if (current > 5) {
current = 0;
}
siteLabel.setText(pageTitle[current]);
repaint();
try {
Thread.sleep(2000);
} catch (InterruptedException exc) {
// do nothing
}
}
}
public void actionPerformed(ActionEvent event) {
Desktop desktop = Desktop.getDesktop();
if (pageLink[current] != null) {
try {
desktop.browse(pageLink[current]);
runner = null;
System.exit(0);
} catch (IOException exc) {
// do nothing
}
}
}
public static viod main(String[] arguments) {
new LinkRotator();
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started