在JavaApp

问题描述 投票:0回答:0
当前,主帧的.java单元的方式:

public class mainFrame extends JFrame { // variable declarations init { // panel content is initialized here // size of mainFrame is set here // pack() is called here // position of mainFrame is set here // mainFrame is made visible here } // initialisation of mainFrame components, event handler methods, etc. main { // this is commented as "the entry point of the program" // some setup stuff, probably important // instance of mainFrame is created here // init method is called here } }

我的问题是: WhereAbout是否应该设置第二帧(即创建的实例)并初始化?可以从这个.java单元完成,还是需要自己的.java + .form组合?

如果可以从大型机单元中完成,则应确切地将其声明,设置,创建,初始化等?它需要自己的初始方法吗?应该将多少原始初始方法复制到新的对应物中?

如果它需要自己的.java + .form组合,是否应该复制大型机的整个.java,然后为全屏进行修订?其中多少需要重复(如果有)?

如果有人可以提供帮助,请很高兴分享指向源存储库的链接。 .Java单元太大了,无法在这里复制整个粘贴。
	

这将是实施两个帧的一种方法。

public class TwoFrames { JFrame frameA; JFrame frameB; JPanel panel; JButton button; boolean showFrameA = false; private void createFrames() { frameA = new JFrame( "frame A" ); frameA.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE ); frameA.setSize( 900, 400 ); frameA.setLocationRelativeTo( null ); frameA.setLayout( null ); frameB = new JFrame( "frame B" ); frameB.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE ); frameB.setExtendedState( Frame.MAXIMIZED_BOTH ); frameB.setUndecorated( true ); frameB.setBackground( new Color( 0, 0, 0, 0.7f ) ); frameB.setLayout( null ); panel = new JPanel(); panel.setSize( 900, 400 ); panel.setBackground( Color.red ); button = new JButton( "switch" ); panel.add( button ); button.addMouseListener( new MouseAdapter() { @Override public void mouseClicked( MouseEvent evt ) { permute(); } } ); permute(); } // this method invert the order of the parameters passed to ‘change’, based on // the value of ‘showFrameA’, then invert your value. private void permute() { if( showFrameA ) change( frameA, frameB ); else change( frameB, frameA ); showFrameA = ! showFrameA; } // this method removes the panel from the frame to be made invisible, adds it // to the other frame, and modifies the invisibility status of each frame void change( JFrame a, JFrame b ) { b.remove( panel ); a.add( panel ); a.setVisible( true ); b.setVisible( false ); } public static void main( String[] args ) { SwingUtilities.invokeLater( new TwoFrames()::createFrames ); } }
    很明显,这里有很多工作要做,例如确定组件的位置等。
java swing jframe fullscreen
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.