import java.awt.*;
import javax.swing.*;
import java.util.*;public class Headlines extends JFrame {
HeadlinePanel news = new HeadlinePanel(); public Headlines() {
super("Headlines");
setSize(420, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel();
pane.setLayout(new GridLayout(1, 1, 15, 15));
pane.add(news);
setContentPane(pane);
show();
news.scroll();
} public static void main(String[] arguments) {
Headlines head = new Headlines();
}
}class HeadlinePanel extends JPanel {
String[] headlines = {
"Grandmother of Eight Makes Hole in One",
"Police Begin Campaign to Run Down Jaywalkers",
"Dr. Ruth to Talk About Sex with Newspaper Editors",
"Enraged Cow Injures Farmer with Axe"
};
int y = 76; void scroll() {
while (true) {
y = y - 1;
if (y < -75)
y = 76;
repaint();
try {
Thread.sleep(250);
} catch (InterruptedException e) { }
}
} public void paintComponent(Graphics comp) {
Graphics2D comp2D = (Graphics2D)comp;
Font type = new Font("monospaced", Font.BOLD, 14);
comp2D.setFont(type);
comp2D.setColor(getBackground());
comp2D.fillRect(0, 0, getSize().width, getSize().height);
comp2D.setColor(Color.black);
for (int i = 0; i < headlines.length; i++)
comp2D.drawString(headlines[i], 5, y + (20 * i));
}}
import javax.swing.*;
import java.util.*;public class Headlines extends JFrame {
HeadlinePanel news = new HeadlinePanel(); public Headlines() {
super("Headlines");
setSize(420, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel();
pane.setLayout(new GridLayout(1, 1, 15, 15));
pane.add(news);
setContentPane(pane);
show();
news.scroll();
} public static void main(String[] arguments) {
Headlines head = new Headlines();
}
}class HeadlinePanel extends JPanel {
String[] headlines = {
"Grandmother of Eight Makes Hole in One",
"Police Begin Campaign to Run Down Jaywalkers",
"Dr. Ruth to Talk About Sex with Newspaper Editors",
"Enraged Cow Injures Farmer with Axe"
};
int y = 76; void scroll() {
while (true) {
y = y - 1;
if (y < -75)
y = 76;
repaint();
try {
Thread.sleep(250);
} catch (InterruptedException e) { }
}
} public void paintComponent(Graphics comp) {
Graphics2D comp2D = (Graphics2D)comp;
Font type = new Font("monospaced", Font.BOLD, 14);
comp2D.setFont(type);
comp2D.setColor(getBackground());
comp2D.fillRect(0, 0, getSize().width, getSize().height);
comp2D.setColor(Color.black);
for (int i = 0; i < headlines.length; i++)
comp2D.drawString(headlines[i], 5, y + (20 * i));
}}
import java.awt.*;
import java.awt.event.*;/*
<APPLET
CODE=scrollborder.class
WIDTH=200
HEIGHT=200 >
</APPLET>
*/public class scrollborder extends Applet implements AdjustmentListener
{ Scrollbar hScroll1, hScroll2, vScroll1, vScroll2;
textPanel t1; public void init()
{
vScroll1 = new Scrollbar(Scrollbar.VERTICAL, 1, 1, 1, 100);
add("West", vScroll1);
vScroll1.addAdjustmentListener(this); hScroll2 = new Scrollbar(Scrollbar.HORIZONTAL, 1, 1, 1, 100);
add("South", hScroll2);
hScroll2.addAdjustmentListener(this); vScroll2 = new Scrollbar(Scrollbar.VERTICAL, 1, 1, 1, 100);
add("East", vScroll2);
vScroll2.addAdjustmentListener(this); t1 = new textPanel();
add("Center", t1);
} public void adjustmentValueChanged(AdjustmentEvent e)
{ if(e.getAdjustable() == hScroll1){
hScroll2.setValue(hScroll1.getValue());
}
if(e.getAdjustable() == vScroll1){
vScroll2.setValue(vScroll1.getValue());
}
if(e.getAdjustable() == hScroll2){
hScroll1.setValue(hScroll2.getValue());
}
if(e.getAdjustable() == vScroll2){
vScroll1.setValue(vScroll2.getValue());
} t1.x = (int) (getSize().width * (float) hScroll1.getValue() / 100);
t1.y = (int) (getSize().height * (float) vScroll1.getValue() / 100);
t1.repaint();
}
}class textPanel extends Panel
{
TextField Text1; public int x = 0, y = 0; public void paint (Graphics g)
{
g.drawString("Hello from Java!", x, y);
}
} 先给你一个不会出的