天道酬勤,学无止境

cardlayout

JFrame whose content changes as we click on the different buttons

I am using Java's Swing here to make a UI application. I have a created a JFrame, with some buttons. When I click on this button, I want a new JFrame with some different content at this place. However, I do not want a new JFrame to load here. One approach, I know is of setting the visbility of the second JFrame to be True in the actionPerformed(ActionEvent obj) method of the button in the first JFrame. But it again loads a new JFrame and I don't want that. public class FirstUI extends JFrame { JButton but1; public FirstUI(){ but1= new JButton("Click here"); add(but1); XYZ obj= new XYZ(): but1

2021-06-24 08:08:27    分类:问答    java   swing   jframe   cardlayout

Java: CardLayout switching between cards

I've got class 'Frame' which extends JFrame and separetad JPanels: MainMenu and SinglePanel I am using CardLayout, but I've got problem when switching back to panels using buttonSingle and powrot buttons. So my question is how can I change/swap between cards using these buttons? My Frame class: public class Frame extends JFrame{ CardLayout cl = new CardLayout(); final MainMenu menuPanel = new MainMenu(); final SinglePanel singlePanel = new SinglePanel(); public Frame(){ setLayout(cl); add(menuPanel,"menu"); add(singlePanel,"single"); setSize(200, 200); setLocationRelativeTo(null)

2021-06-22 18:35:20    分类:问答    java   swing   cardlayout

卡片视图点击卡片移动到新活动(Card View Click on Card Move To New Activity)

问题 我是 Android 编程的新手,正在研究卡片布局。 我想知道,我如何使它可点击? android:clickable="true" android:foreground="?android:attr/selectableItemBackground" 我的卡片小部件上有它,然后我想知道在哪里放置可点击的操作? 我希望能够点击卡片,它获取卡片的 id,然后显示一个新的意图活动 这是我用于加载适配器的活动的代码 setContentView(R.layout.activity_my); RecyclerView recList = (RecyclerView) findViewById(R.id.cardList); recList.setHasFixedSize(true); LinearLayoutManager llm = new LinearLayoutManager(this); llm.setOrientation(LinearLayoutManager.VERTICAL); recList.setLayoutManager(llm); ContactAdapter ca = new ContactAdapter(createList(30)); recList.setAdapter(ca); 回答1 如果你正确使用了实现,你的代码应该是这样的: card - is

2021-06-12 21:30:23    分类:技术分享    android   cardlayout

How to Switch between Panels in CardLayout from ActionListeners in external classes

I have a cardLayout in the main class that the Gui classes are added to layout via panels and when the Room1Button is pressed how would it switch the card in the main method to the Gui2 card is this the best way to go about this any help would be apreatiated Main Method import javax.swing.*; import java.awt.*; class Main { CardLayout cl=new CardLayout(); GridBagConstraints gb=new GridBagConstraints(); JFrame frame=new JFrame("Frame"); JPanel panel =new JPanel(); Gui1 g1= Gui1(); Gui2 g2= Gui2(); public Main() { panel.setLayout(cl); panel.add(g1, "1"); panel.add(g2, "2"); frame.add(panel)

2021-06-12 10:14:07    分类:问答    java   swing   actionlistener   cardlayout

JPanel 和 CardLayout 的 NullPointerException 错误(NullPointerException Error with JPanel and CardLayout)

问题 我正在为课堂开发酒店管理软件,但我的代码遇到了一些问题。 在这一点上,我只是想将我在单独的类中创建的 JPanel 添加到我的主 gui 中。 任何帮助将不胜感激。 ~谢谢! Exception in thread "main" java.lang.NullPointerException at java.awt.Container.addImpl(Unknown Source) at java.awt.Container.add(Unknown Source) at hotelManage.HotelSystem.showGUI(HotelSystem.java:75) at hotelManage.HotelSystem.<init>(HotelSystem.java:27) at hotelManage.HotelSystem.main(HotelSystem.java:115) 注意:错误发生在“jpanel.add("Room", room.getRoomPanel());”行 代码:HotelSystem.java import java.awt.*; import java.awt.event.*; import javax.swing.*; public class HotelSystem extends JFrame implements

2021-06-11 20:36:27    分类:技术分享    java   swing   null   jpanel   cardlayout

如何将 CardLayout 用于我的 Java 程序以进行登录和菜单项(How do I use CardLayout for my Java Program for Login and Menu Items)

问题 我正在创建一个“商店”程序,它基本上可以允许员工使用我提供的用户名和密码登录。 登录后,员工可以看到带有四个按钮的“主菜单”:销售登记、PLU 设置、设置和注销。 在此屏幕上,员工可以通过单击任何按钮导航到该屏幕来继续操作。 我不希望每次单击按钮时都弹出一个新窗口,而是希望有一些过渡(或没有过渡)可以转到被单击的页面。 举个例子:当员工启动程序时,他/她会看到登录菜单。 然后员工输入他/她的登录信息并点击登录。 如果信息不正确,系统会提示员工重新输入信息。 如果信息正确,员工现在将被发送到主菜单。 在主菜单上,员工选择“销售登记”,程序进入销售登记。 所有这一切都应该发生在一个窗口中。 到目前为止,我已经添加了我能够做的代码。 我已经创建了所有按钮和标签,但我无法让它们显示在 JFrame 上并使用 CardLayout。 另外,我不知道如何将登录代码与 CardLayout 联系起来。 感谢你们对我的帮助。 这是代码: 主菜单代码 (storeMainMenu.java) import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class storeMainMenu implements

2021-06-10 10:55:09    分类:技术分享    java   sql   swing   jframe   cardlayout

CardLayout 的父容器/面板(Parent container/panel for a CardLayout)

问题 我如何获得CardLayout任何面板的“容器”面板。 也就是说,如果一个面板是另一个“容器”面板中的卡片,那么如何从卡片中获取对这个“容器”面板的引用? 这是我在做什么:- public class LogInPanel extends javax.swing.JPanel implements ActionListener{ /** * Creates new form Panel2 */ private JPanel parentPanel; private CardLayout c1=null; public LogInPanel() { initComponents(); //c1=new CardLayout(); parentPanel=(JPanel)(SwingUtilities.getAncestorOfClass(this.getClass(), this)); c1=(CardLayout)(parentPanel.getLayout()); submitLogin.addActionListener(this); } ... 回答1 您可以使用Component超类提供的方法 getParent。 对于您的卡片面板,只需调用panel.getParent()它将为您提供包含(父)面板。

2021-06-09 16:36:00    分类:技术分享    java   swing   jpanel   layout-manager   cardlayout

How to reload a JPanel?

I'm a java newbie... I need to know how to reload a JPanel? I extended the JPanel class and created a panel that will run in a cardlayout in an Applet. I want this panel to reload/refresh after the user clicks a button in this panel. I tried including the revalidate() and repaint() methods (methods I don't understand well) in the ActionListener for the button but nothing happened. Can anyone throw some light on how to correctly refresh the whole panel?

2021-06-09 12:52:20    分类:问答    java   swing   jpanel   cardlayout

使用摆动滑动效果更改卡片布局中的当前卡片(Change current card in card layout with slide effect in swing)

问题 我正在尝试使用幻灯片效果更改卡片布局中的当前可见。 但是我在幻灯片的开头看到了一个我无法调试/解决的轻弹。 我怎样才能避免那部电影? 这是重现错误的示例代码: import java.awt.CardLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class Main { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new CardLayout()); JLabel label1 = new JLabel("Harry Joy"); panel.add(label1, "1"); JLabel label2 = new JLabel("Harsh Raval"); panel.add(label2, "2"); frame.add(panel); frame.pack(); frame.setVisible(true); for (int i = 0; i < 10; i++) {

2021-06-03 03:10:01    分类:技术分享    java   swing   cardlayout

Card View Click on Card Move To New Activity

I am new to Android programming and was working on a card layout. I was wondering, how do I make it clickable? android:clickable="true" android:foreground="?android:attr/selectableItemBackground" I have that on my card widget and then I wanted to know where to put an on clickable action? I want to be able to click the card, it gets the id of the card, and then displays a new intent activity This is my code for the activity to load the adapter setContentView(R.layout.activity_my); RecyclerView recList = (RecyclerView) findViewById(R.id.cardList); recList.setHasFixedSize(true)

2021-05-25 15:56:56    分类:问答    android   cardlayout