Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to open new Jframe form another class by clicking a Jbutton
    primarykey
    data
    text
    <p>(I just started programming in java.) So here is my code!</p> <pre><code>Main: import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import javax.swing.JButton; import javax.swing.JOptionPane; import javax.swing.JFrame; public class buttons {{ /*Frame creation*/ final JFrame frameKontrast = new JFrame(); frameKontrast.setTitle("Main Menu"); frameKontrast.setSize(500,350); frameKontrast.setLocationRelativeTo(null); frameKontrast.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); /*JPanel creation*/ JPanel panel = new JPanel (); panel.setLayout(new GridLayout(0, 1)); /*Okno dialogowe*/ final JLabel dialog = new JLabel(); dialog.setText("&lt;html&gt;Jestem bardzo długim bezsensownym dialogiem mam nawet kolejną bardzo długą bezsensowną część która istnieje tylko po to, by ten tekst był ow wiele, wiele dłuższy niż wszystkie inne oraz aby zmusić się do napisania skryptu ktory robi enter w tekście. Koniec.&lt;/html&gt;"); JMenuBar menuKontrast = new JMenuBar(); frameKontrast.setJMenuBar(menuKontrast); /*Przyciski wyboru*/ final JButton przyciskb = new JButton(); przyciskb.setText("Exit"); final JButton przyciska = new JButton(); przyciska.setText("Start the game"); /*Rozwijane menu (zadania)*/ JMenu objectives = new JMenu("Objectives"); JMenuItem zad1 = new JMenuItem("Zadanie numer 1"); JMenuItem zad2 = new JMenuItem("Zadanie numer 2"); JMenuItem zad3 = new JMenuItem("Zadanie numer 3"); /*Dołączanie obiektów do GUI*/ panel.add(dialog); menuKontrast.add(objectives); objectives.add(zad1); objectives.add(zad2); objectives.add(zad3); ButtonGroup group = new ButtonGroup(); group.add(przyciska); group.add(przyciskb); panel.add(przyciska); panel.add(przyciskb); frameKontrast.getContentPane().add(panel); frameKontrast.getContentPane().add(panel); frameKontrast.setVisible(true); }}; </code></pre> <p>And here is a new window that I want to open by the przyciska button:</p> <pre><code> public class frameKontrastGame {{ { JFrame frameKontrastGame = new JFrame(); frameKontrastGame.setTitle("Kontrast"); frameKontrastGame.setSize(1000,700); frameKontrastGame.setLocationRelativeTo(null); frameKontrastGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel (); panel.setLayout(new GridLayout(0, 1)); JLabel dialog = new JLabel(); dialog.setText("&lt;html&gt;Kontrast&lt;/html&gt;"); JMenuBar menuKontrast = new JMenuBar(); frameKontrastGame.setJMenuBar(menuKontrast); frameKontrastGame.setVisible(true); panel.add(dialog); frameKontrastGame.getContentPane().add(panel); frameKontrastGame.getContentPane().add(panel); frameKontrastGame.setVisible(true); }}} </code></pre> <p>I know that its not the best code. It's working and I'm pleased with it. My problem is that I cant use "this" listeners. I hope that someone have a little time to help me with this simple problem. Thanks for reading all of this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload