Tag: cardlayout

在cardlayout中切换卡后运行方法

我确定之前有人问过这个问题,但今天我的google-fu并不强大。 我有一个使用CardLayout作为其管理器的JFrame。 当我在不使用开关的情况下切换到每个JPanel时,如何运行“开始”方法? 我用来将帧添加到布局的代码是: /** * Adds JPanels to the Card Layout. * @param panel is the JPanel to add to the layout. * @param windowName is the identifier used to recognise the Panel. */ public final void addToCards(final JPanel panel, final WindowNames windowName) { view.getBasePanel().add(panel, windowName.getValue()); } 我用来切换布局的代码是: /** * Method to change the […]

java GUI中的CardLayout()

在我的代码中,目前每张卡都是我的框架的大小。 如何在布局中设置每个面板的不同尺寸。 我尝试通过调用run()方法并更改框架的大小来使框架具有不同的大小,但它不起作用。 我希望还有另一种方式。 这是我的代码: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class GameManager { JFrame frame; JPanel cards,Title; public GameManager() { cards = new JPanel(new CardLayout()); Title title = new Title(); cards.add(title,”title”); CardLayout cl = (CardLayout)(cards.getLayout()); cl.show(cards, “title”); } public static void main(String [] args) { GameManager gm = new GameManager(); gm.run(); […]

CardLayout,通过ButtonClick在JPanel之间切换

我想通过点击JPanels上的按钮在JPanel之间切换。 例如:我有一个带有JButton simknop的JPanel sim和带有JButton helpknop的JPanel帮助我想通过单击按钮在这两个JPanel之间切换。 当我点击JButton simknop时,应该出现JPanel帮助,当我点击JButton时,应该会出现JPanel sim。 您可以在下面找到不同的类: main.java public class main extends JFrame { JPanel cards; sim sim; help help; public main() { this.setSize(1024,768); //this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setTitle(“Crazy Bombardement”); this.setLocation(800, 100);//standaard in de hoek van het scherm cards = new JPanel(); cards.setLayout(new CardLayout()); sim = new sim(); help = new help(); cards.add(sim, […]

在卡布局内定位组件

我有一个主框架,我想用卡片布局在中心位置显示我的NewUser类的对象。这是我的主要课程 import java.awt.*; import java.awt.event.*; import javax.swing.*; public class CardLayoutDemo implements ItemListener { JPanel cards; //a panel that uses CardLayout final static String BUTTONPANEL = “Card with JButtons”; final static String TEXTPANEL = “Card with JTextField”; public void addComponentToPane(Container pane) { //Put the JComboBox in a JPanel to get a nicer look. JPanel comboBoxPane = […]

如何设置JFrame大小以适合显示JPanel的CardLayout?

我在CardLayout中有一个包含一组JPanels的JFrame 。 每个JPanel都有不同的大小,我希望JFrame适应当前显示的JPanel的大小(而不是JPanel以适应JFrame的大小)。 我怎样才能做到这一点?

使用卡布局更改面板

嗨,我很抱歉,如果这已经发布但我看起来很难找到其他代码,我无法理解。 我是java编程的新手,并希望有人指出我如何通过按下按钮更改为所需的面板。 任何帮助将受到高度赞赏。 我只想完全理解这个概念是如何工作的。 import java.awt.*; import java.awt.event.*; import javax.swing.*; // Packages used in this program imported public class onlineGame extends JFrame implements ActionListener { JPanel cards; JButton button1, button2, button3; public onlineGame() //This is the CONSTRUCTOR method { //The entry point into your program setLayout(new FlowLayout()); //Use this for now. setSize(810, 510); //Set the […]

当另一个类调用Singleton.instance.show()时,带有CardLayout的Singleton将不会显示卡片

public class MainWindow extends JPanel { public static MainWindow instance = new MainWindow(); private CardLayout cards = new CardLayout(); public MainWindow() { setLayout(cards); add(new FirstPage(), Pages.FIRST.toString()); add(new SecondPage(), Pages.SECOND.toString()); add(new ThirdPage(), Pages.THIRD.toString()); } public void showPage(Pages page) { cards.show(this, page.toString()); } } showPage(page); 如果我在MainWindow的构造函数中调用它,方法工作正常。 但是当我尝试调用MainWindow.instance.showPage(Pages.SECOND); 来自FirstPage的ActionListener没有任何反应。 我已经检查过showPage(page)方法是否正常工作。 我已经检查过ActionEvent被触发并输入正确的if / else子句。 我做错了什么,为什么不是我的第二页显示? public class FirstPage extends […]

当第二个JPanel添加时,Java CardLayout JPanel向上移动

我是Java新手,主要是CardLayout。 我想简单地切换由JPanels代表的“windows”。 我在CardLayout上找到了那份工作。 但我的问题是,当add chatPanel到mainPanel (这是CardLayout)时,它会将connectPanel几个像素的内容connectPanel顶部,远离其居中位置。 我是否在我的代码createChatPanel(),跳过它应该在的位置。 我有这个代码: package App; import java.awt.CardLayout; import java.awt.Dimension; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import Validators.*; public class GUI { private JFrame mainFrame = null; private JPanel mainPanel = null; private CardLayout cl = new CardLayout(); public GUI(){ try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (UnsupportedLookAndFeelException e) { } […]

如何在继续之前等待JFrame关闭?

我的程序包含3个主要“部分”。 主要function,登录表格和App表格。 主要function应该是这样的:打开登录表单,等待它关闭,然后打开App表单。 我不能让等待的部分工作,或者更确切地说,我不知道如何去做这件事。 有人告诉我使用JDialog而使用setModal(true) ,但是使用这种方法,Login表单不会出现在任务栏上,这在我看来很糟糕。 我考虑的另一件事是在关闭后从Login内部打开应用程序,但这感觉就像糟糕的设计,因为这会使登录表单不可重用。 那么,拜托,你会建议什么?

如何在CardLayout中显示不同的卡?

我查看了使用此代码的代码示例: cl.show(cardPanel, “” + (currentCard)); 但是当我使用show时,我在Eclipse中收到一条消息,它已被弃用,我想知道当我点击按钮时是否还有另一种方法可以显示CardLayout中的不同卡片? 下面是我的CardLayout类的代码。 如果代码的某些部分是不好的做法,也欢迎提出建议。 谢谢! import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class CardLayoutTest extends JFrame implements ActionListener { // Ref private JPanel cardPanel, jp1, jp2, buttonPanel; private JLabel jl1, jl2; private JButton btn1, btn2; private CardLayout cardLayout; // Konstruktor public CardLayoutTest() { setTitle(“Test med CardLayout”); setSize(600,400); cardPanel = […]