Eksempel på opbygning som fungerer:
(skal naturligvus samles med andre filer for at virke, men princippet er der
stadig!)
import javax.swing.*;
import java.awt.*;
public class BrowserView extends JFrame {
public final JButton HOME;
public final JButton BACK;
public final JButton FORWARD;
public final JButton QUIT;
public final JButton UP;
public final JButton DOWN;
public final JButton OPEN;
private JTextField LOCATION;
private JLabel STATUS;
private JLabel TITLE;
private JLabel MYTITLE;
/** Browser konstruerer et Browservindue med
* (1) kontrol- og scrollknapper
* (2) status,titel,location info
* (3) delvindue med display
* @param width vinduets bredde
* @param height vinduets højde
* @param d display komponenten
*/
BrowserView(int width, int height, BrowserDisplay d) {
file://INSERT
file://initialisering
HOME = new JButton("HOME");
BACK = new JButton("BACK");
FORWARD = new JButton("FORWARD");
QUIT = new JButton("QUIT");
UP = new JButton("SCROLLUP");
DOWN = new JButton("SCROLLDOWN");
OPEN = new JButton("OPEN");
LOCATION = new JTextField("", 55);
STATUS = new JLabel("");
TITLE = new JLabel("");
MYTITLE = new JLabel("__________I N T E R N E T E X P L O I D E
R__________");
file://ContentPane
Container cp = getContentPane();
cp.setLayout(new BorderLayout());
file://ContentPane NORTH
JPanel cpN = new JPanel(new GridLayout(4,1));
file://ContentPane NORTH 1
JPanel cpN1 = new JPanel(new FlowLayout());
file://cpN1.setForeground(Color.white);
file://cpN1.setBackground(Color.blue);
cpN1.add(MYTITLE).setForeground(Color.black);
file://ContentPane NORTH 2
JPanel cpN2 = new JPanel(new FlowLayout(0));
cpN2.add(BACK);
cpN2.add(FORWARD);
cpN2.add(HOME);
cpN2.add(QUIT);
file://ContentPane NORTH 3
JPanel cpN3 = new JPanel(new FlowLayout(0));
cpN3.add(LOCATION);
cpN3.add(OPEN);
file://ContentPane NORTH 4
JPanel cpN4 = new JPanel(new FlowLayout());
cpN4.add(TITLE);
cpN.add(cpN1);
cpN.add(cpN2);
cpN.add(cpN3);
cpN.add(cpN4);
cp.add(cpN, BorderLayout.NORTH);
JPanel cpW = new JPanel(new FlowLayout());
file://cpW.add(BACK);
cp.add(cpW, BorderLayout.WEST);
JPanel cpC = new JPanel(new FlowLayout());
cpC.setBackground(Color.white);
cpC.add(d);
cp.add(cpC, BorderLayout.CENTER);
JPanel cpE = new JPanel(new FlowLayout());
file://cpE.add(FORWARD);
cp.add(cpE, BorderLayout.EAST);
JPanel cpS = new JPanel(new GridLayout(2,1));
JPanel cpS1 = new JPanel(new FlowLayout());
JPanel cpS2 = new JPanel(new FlowLayout());
cpS1.add(UP);
cpS1.add(DOWN);
cpS2.add(STATUS).setForeground(Color.black);
cpS.add(cpS1);
cpS.add(cpS2);
cp.add(cpS, BorderLayout.SOUTH);
file://addWindowListener(new ExitController());
setTitle("dIntProg - Browser opgave. Leon Jessen MD1 u001657");
setSize(width,height);
setVisible(true);
}
/** showStatus viser en statustekst i browservinduet
* @param s tekst der skal vises */
public void showStatus(String s) {
file://INSERT
STATUS.setText(s);
}
/** showStatus viser titlen på et htmldokument i browservinduet
* @param s titlen der skal vises */
public void showTitle(String s) {
file://INSERT
TITLE.setText("This site's title: "+s);
}
/** showLocation viser en url i browservinduets locationfelt
* @param s den url-tekst der skal vises */
public void showLocation(String s) {
file://INSERT
LOCATION.setText(s);
}
/** getLocation returnerer den url (i tekstform) der vises i
* browservinduet
* @return url-teksten der fremvises i location-feltet */
public String getLocationText() {
file://INSERT
return (LOCATION.getText());
}
}
--
___________________________
Glædelig Jul *<|
Med venlig hilsen
Stud. Scient.
Leon I. Jesse