简体   繁体   English

gui选项卡式窗格-如何将内部类放入选项卡式窗格

[英]gui tabbed pane - how to put a inner class into my tabbed pane

this is a homework and currently stuck on how to put inner class into my tabbed pane. 这是一项家庭作业,目前停留在如何将内部类放入选项卡式窗格中。

Currently i have my main page which is the tabbed pane which the user will select accordingly to the pane. 目前我有我的主页,它是选项卡式窗格,用户将相应地选择该窗格。

Below is my tabbed pane class and further down is my ticket class. 下面是我的选项卡式窗格类,而下面是我的票证类。 Currently i have created a inner class called Booking() in my Ticket() class. 目前,我已经在我的Ticket()类中创建了一个称为Booking()的内部类。 The problem now is how do i call and use it in my tabbed pane class 现在的问题是如何在选项卡式窗格类中调用和使用它

Tickets t1 = new Booking() 门票t1 =新订票()

tp.addTab("Booking", t1.Booking()); tp.addTab(“ Booking”,t1.Booking());

This 2 code i have added in my code but it is giving my errors. 我在代码中添加了这2个代码,但是却给了我错误。 So my question is how to use the inner class (Booking()) which is inside of Ticket class and use it in my tabbed pane. 所以我的问题是如何使用Ticket类内部的内部类(Booking())并在我的选项卡式窗格中使用它。

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

public class tabbedThemePark{

    public static void main(String[] args){

    JFrame frame = new JFrame("RR THEME PARK");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTabbedPane tp = new JTabbedPane();

    tp.addTab("Intro",new IntroPanel());
    tp.addTab("Tickets",new Tickets());
    Tickets t1 = new Booking();
    tp.addTab("Booking", t1.Booking());

    frame.add(tp);
    frame.pack();
    frame.setVisible(true);
    }

 }

This is my ticket class 这是我的机票舱位

public class Tickets extends JPanel
{
  public Tickets()
  {
      //coding
  }

  public class Booking
  {
     public Booking()
     {
      //coding
     }
  }
}

The line 线

Tickets t1 = new Booking();

does not make sense because Booking is not a subclass of Tickets , but an inner class. 没有意义,因为Booking不是Tickets子类 ,而是内部类。 You would first need to create a Tickets instance, and then create a new Booking instance within it. 您首先需要创建一个Tickets实例,然后在其中创建一个新的Booking实例。

Like so 像这样

Tickets t1 = new Tickets();
tp.addTab("Booking", t1.new Booking());

Refer to this for help on Nested Classes . 请参考此以获取有关嵌套类的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM