In the following code, I want to make a small screen that has a piece of text in it using JFrame
. Why does not this code work?
package notepad;
import javax.swing.JFrame;
public class Notepad extends JFrame{
public Notepad(){
setTitle("Notepad");
setSize(250, 250);
setResizable(false);
setVisible(true);
}
public static void main(String[] args){
new Notepad();
System.out.println("Hello World!", 75, 75);
}
}
If you look at the System.out.println("Hello World!", 75, 75);
why does the 75, 75 not work? How do I make the text go there?
printLn
outputs a line of text to the console window. To put text into the UI window you would need to create a JLabel
and add it to your JFrame
.
public Notepad(){
setTitle("Notepad");
setResizable(false);
add(new JLabel("This will be on your UI window"))
setVisible(true);
pack();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.