// Eine einfache grafische Benutzeroberfläche mit Swing
//von der Zeile 3 bis zur Zeile 5; Impotieren von Bibliothek
import java.awt.*;
import javax.swing.*;
import java.awt.Graphics;
public class HelloGUI extends JFrame { // public class HelloGui
public HelloGUI (String title) {
super(title);
getContentPane().add("North",new JButton("Hello World"));
setSize(400,400);
setVisible(true);
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
public void paint (Graphics g) {
/* Das Verwenden von pain Methode
* Graphics ist ein Parameter
* in g ist das Parameter Graphics gespeichert
*/
String insideRect = "Hello World!";
//this String should be displayed inside of the rectangel
}
public static void main(String args[]) {
new HelloGUI("Hello World ");
}
}
0 Antworten
I want to write a simpl java gui App, which display the Strin "Hello world", but it is very important to me that "Hello world" must be inside a rectangle.
so used the method g.drawRect()
to draw a rectangle and the method g.drawString()
to display the String "Hello World!" or any other message.
The Code work , but Hello World is not displayed iside the reactangle.
Can anybody help me to display the string "Hello Wolrd!"inside the rectangle... I try it but it didn't work. that is my code! tnx
so here is a screenshot of my result