在容器中插入JLabel。

huangapple 未分类评论59阅读模式
英文:

Insertion of a JLabel in a container

问题

import java.awt.*;
import javax.swing.*;

public class Esercizio7 {
    public static void main(String[] v){
        JFrame f = new JFrame("Prenota il tuo biglietto!");
        Container c = f.getContentPane();
        JPanel panel = new JPanel();
        c.add(panel);
        f.setSize(new Dimension(500,350));
        f.show();
    }
}

public class Testo extends JPanel {
    public Testo(){
        super();
        JLabel l = new JLabel("srgsgsrg");
        add(l);
    }
}
英文:

I have to create a window with a graphical interface in Java using Swing. Here I have tried to maximize and rename the window and this works. The problem is that then I tried to insert a JLabel but nothing is seen, why?

 package esercizio7;

import java.awt.*;
import javax.swing.*;
public class Esercizio7 {

public static void main(String[] v){
JFrame f = new JFrame("Prenota il tuo biglietto!");
Container c = f.getContentPane();
JPanel panel = new JPanel();
c.add(panel);
f.setSize(new Dimension(500,350));
f.show();
}}




public class testo extends JPanel {
public testo(){
super();
JLabel l = new JLabel("srgsgsrg");
add(l);}}

huangapple
  • 本文由 发表于 2020年5月3日 22:24:33
  • 转载请务必保留本文链接:https://java.coder-hub.com/61576052.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定