且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

以编程方式在JFrame中交换两个JPanel

更新时间:2023-12-05 08:34:10


  • 不需要将 JPanels 移动到容器中,否则你需要使用大量无用的代码来删除两个来自带有两个索引的contianer的 JPanels 然后使用交换索引布局回容器

    • there wouldn't need to move with JPanels into container, otherwise you woud need to use bunch of quite useless code to remove two JPanels from from contianer with two indexes then to layout back to container with swaping indexes,

      (仅限于 Color )仅交换 setBackground(Color.Xxx)两个之间 JPanels

      (if is about Color only) only to swap setBackground(Color.Xxx) betweens two JPanels

      类似益智游戏约为图像,拼图或minesweaper即将发布,(不清楚...)

      puzzle-like game is about Images, puzzle or minesweaper is about, (not clear from your ...)


      1. 图像设为图标/ ImageIcons JLabel 而不是 JPanel 鼠标事件切换( setIcon())与图标之间 JLabels ,加载图标到本地变量

      1. put Images as Icon/ImageIcons to JLabel instead of JPanel and on Mouse Events to switch (setIcon()) with Icons betweens JLabels, load Icons to local variables

      (最简单的方法) JToggleButton和Icon ,有 JLabel 的逻辑类似物,但是关于在上显示图标 setPressedIcon()

      (easiest of ways) JToggleButton and Icon, there is logic similair as for JLabel, but about showing Icon on setPressedIcon()