Re: JScrollPane in Applet
- From: Lukasz <fatmouseREMOVEIT@xxxxxxxxx>
- Date: Thu, 13 Jul 2006 22:15:35 +0200
[cut]
import java.io.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.*;
import java.sql.*;
import javax.swing.*;
/*
<APPLET CODE="ShortVersion.class" WIDTH="1000" HEIGHT="500">
</APPLET>
*/
public class ShortVersion extends Applet implements ActionListener {
ResultSet rs;
Statement s;
Button button, back;
int op = 0;
JScrollPane scrollPane;
JTable table;
String[] columnNames = {"A", "B", "C"};
int size = 100;
String[][] data = new String[size][3];
public void init() {
button = new Button("Click me");
button.addActionListener(this);
button.setBounds(10,90,130,30);
add(button);
back = new Button("Back");
back.addActionListener(this);
back.setBounds(10, 300, 130, 30);
table = new JTable(data, columnNames);
table.setPreferredScrollableViewportSize(new Dimension(500, 100));
scrollPane = new JScrollPane(table);
add(scrollPane);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button) {
removeAll();
repaint();
add(back);
op = 1;
} else if (e.getSource() == back) {
removeAll();
repaint();
menu();
op = 0;
}
}
public void paint(Graphics g) {
super.paint(g);
if (op == 1) {
try {
int t = 0;
data[t][0] = "text1";
data[t][1] = "text2";
data[t][2] = "text3";
if (t == size) {
String[][] temp = new String[size * 2][3];
System.arraycopy(data, 0, temp, 0, data.length);
data = temp;
temp = null;
}
t++;
} catch (Exception error) {
error.printStackTrace();
g.drawString("Error while querying", 250, 250);
}
add(scrollPane);
}
}
public void menu() {
add(button);
}
}
And here, if that would be needed, a HTML code:
<HTML>
<HEAD></HEAD>
<BODY>
<CENTER><APPLET
CODE="shortVersion.class"
WIDTH="900"
HEIGHT="600"
>
</APPLET></CENTER>
</BODY>
</HTML>
I hope that this would be compilable and runnable for You. There is no longer connection with the database.
.
- Follow-Ups:
- Re: JScrollPane in Applet
- From: andrewthommo
- Re: JScrollPane in Applet
- From: andrewthommo
- Re: JScrollPane in Applet
- References:
- Re: JScrollPane in Applet
- From: andrewthommo
- Re: JScrollPane in Applet
- Prev by Date: Re: Problem with JOptionPane and JComboBox....
- Next by Date: Re: JScrollPane in Applet
- Previous by thread: Re: JScrollPane in Applet
- Next by thread: Re: JScrollPane in Applet
- Index(es):