How to run a program in textpad?

Using the Java SDK with TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Textmad

How to run a program in textpad?

Post by Textmad »

I have problems wit run this (and some other) program in Textpad. But others work well. Just cant figure out whats wrong. I think the code is okay. But heard something about, main has to be in the start of the project to get it work in textpad. Someone who know something about this?
txh!


import java.awt.*; // klassene Color og Graphics
import javax.swing.*; // klassene JFrame og JPanel

class Vindu extends JFrame {
public Vindu(String tittel) {
setTitle(tittel);
setSize(500, 250); // bredde, høyde
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Tegning tegningen = new Tegning();
add(tegningen);
}
}

class Tegning extends JPanel {
public void paintComponent(Graphics tegneflate) {
super.paintComponent(tegneflate);
tegneflate.drawString("Fargen grå, som først blir lysere, deretter mørkere", 40, 30);
Color farge = Color.gray;
tegneflate.setColor(farge);
tegneflate.fillRect(40, 50, 20, 120);
farge = farge.brighter();
tegneflate.setColor(farge);
tegneflate.fillRect(60, 50, 20, 120);
farge = farge.brighter();
tegneflate.setColor(farge);
tegneflate.fillRect(80, 50, 20, 120);
farge = farge.darker();
tegneflate.setColor(farge);
tegneflate.fillRect(100, 50, 20, 120);
farge = farge.darker();
tegneflate.setColor(farge);
tegneflate.fillRect(120, 50, 20, 120);
}
}

class FargeDemo {
public static void main(String[] args) {
Vindu etVindu = new Vindu("Farger i forskjellige nyanser");
etVindu.setVisible(true);
}
}
_________________
Post Reply