Java open a new GUI window đ
VloĆŸit
- Äas pĆidĂĄn 27. 07. 2024
- Java new window
#java #new #window
// **********************************************
public class Main {
public static void main(String[] args) {
LaunchPage launchPage = new LaunchPage();
}
}
// **********************************************
import java.awt.event.*;
import javax.swing.*;
public class LaunchPage implements ActionListener{
JFrame frame = new JFrame();
JButton myButton = new JButton("New Window");
LaunchPage(){
myButton.setBounds(100,160,200,40);
myButton.setFocusable(false);
myButton.addActionListener(this);
frame.add(myButton);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(420,420);
frame.setLayout(null);
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==myButton) {
frame.dispose();
NewWindow myWindow = new NewWindow();
}
}
}
// **********************************************
import java.awt.*;
import javax.swing.*;
public class NewWindow {
JFrame frame = new JFrame();
JLabel label = new JLabel("Hello!");
NewWindow(){
label.setBounds(0,0,100,50);
label.setFont(new Font(null,Font.PLAIN,25));
frame.add(label);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(420,420);
frame.setLayout(null);
frame.setVisible(true);
}
} - VÄda a technologie
// **********************************************
public class Main {
public static void main(String[] args) {
LaunchPage launchPage = new LaunchPage();
}
}
// **********************************************
import java.awt.event.*;
import javax.swing.*;
public class LaunchPage implements ActionListener{
JFrame frame = new JFrame();
JButton myButton = new JButton("New Window");
LaunchPage(){
myButton.setBounds(100,160,200,40);
myButton.setFocusable(false);
myButton.addActionListener(this);
frame.add(myButton);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(420,420);
frame.setLayout(null);
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==myButton) {
frame.dispose();
NewWindow myWindow = new NewWindow();
}
}
}
// **********************************************
import java.awt.*;
import javax.swing.*;
public class NewWindow {
JFrame frame = new JFrame();
JLabel label = new JLabel("Hello!");
NewWindow(){
label.setBounds(0,0,100,50);
label.setFont(new Font(null,Font.PLAIN,25));
frame.add(label);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(420,420);
frame.setLayout(null);
frame.setVisible(true);
}
}
2 420'S?!?
Practicing...
public class Main{
public static void main(String[ ]args){
LaunchPage launchPage = new LaunchPage();
}
}
************************
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class LaunchPage implements ActionListener
{
JFrame frame = new JFrame ();
JButton button = new JButton ("New Window");
LaunchPage ()
{
button.setBounds (100, 160, 200, 40);
button.setFocusable (false);
button.addActionListener (this);
frame.add(button);
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.setSize (400, 400);
frame.setLayout (null);
frame.setVisible (true);
}
@Override public void actionPerformed (ActionEvent e)
{
if(e.getSource()==button){
frame.dispose();
NewWindow window = new NewWindow();
}
}
}
******************
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class NewWindow
{
JFrame frame = new JFrame ();
JLabel label = new JLabel ("Salut!");
NewWindow ()
{
label.setBounds (0, 0, 100, 50);
label.setFont (new Font ("Times New Roman", Font.PLAIN,12));
frame.add(label);
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.setSize (400, 400);
frame.setLayout (null);
frame.setVisible (true);
}
}
This is the best Java tutorial for beginners, so you can learn Java and English in one hit. Please keep going! I vote for Java advance tutorial. Thanks a lot Bro
another great video! i'm about to be up to date with your series!
Thanks man exactly the solution to my problem! I am glad i subbed to you!
Awesome tut bro looking forward for more tuts like this đ
Bro, thanks a lot for your wonderful tutorials
Thanks, I'm working on a project, you are helping me a lot
Just found your channel through this video, with all the great content how could I not subscribe?
this was soo helpful, thank you!
You don't know how much it helped!
this helped me a ton, thanks!
Bro you helped me a LOT . Thanks man
You earned yourself a sub... thank you so much broski
Thank you very much bro, you helped me out of a problem with this tutorial.
Finally at tutorial that explains what happens in the process
OMG thank you so much this help me a lot i tried to open a window with other events but didn't work, I see your video a work inmediatly
Heey Bro , you are awesome , your way of teaching is very nice..
I smashed the like button, that my phone screen is gonna crack..
Thanks man, it worked!
This is interesting and it helps, thank you
You just saved my proyect!! I LOVE YOU!!
awesome!! thanks for watching Charlie!
I love how you say "button"!
Helpful and compact.
Nice tutorial bro thanks!
muchas gracias por tus videos. Aprendo varias cosas....
Very nice video, I like it very much. 40 degrees Celsius, drink beer đđđ
A fine tutorial !!
You are doing great manâ€
Thank you for the content
Hey Bro Code, please do videos on constructors(their types), and objects in Java
I think I might have a video on what you're looking for here:
czcams.com/video/J4g6iuKoo_0/video.html
Amazing tutorial
awesome ! thanks
Bro that's the code đI've definitely smashed that like button
awesomeđ
Amazing video
Great đ
awesome!
wow that frame.setSize parameters must be really coincidence :P
thanks bro
YOU'RE THE BEST CZcamsR EVER!!
Youâre a legend Bro
another great vid
Thanks đ
thanks for this...
Perfect
Thank you bro
Please make videos for mobile app development đ đ
our lord and savoir is here
Nice, bro!
it's so easy thanks
Thanks
thank you bro
New subscriber heređ
thank broooo
best man
tnx a lot
iâm a student and iâm learning from my college that is called Bro Code and itâs free
Same
TYSM
the tutorial is very help full...
how can you make the button to link with another website like "click here to access Gmail account?"
idk how to use jframe but maybe u know how to do this in window builder if i already got 2 windows?
Good job Bro
I have an assignment where the first window needs to be closed after pressing okay button on the second window, like the second window needs to have a button that makes the first window close after it being pressed, im going crazy
Hey bro i know this is late but can you explain why you need 3 file instead of 2 only?
i understand this part, but how does the package actually create the window?
can u please help,
i want to add 4 window, what should i do.
thanks for the help
can you plz sent another video to Java open a new GUI window with hiding first one
is there a way to choose where on the screen the window will appear?
Hello!
As always, another great video. Question please: I do not want to dispose of the main front window, but I would like to limit the pop up to one instance. how? I intend to have several buttons on the front page, each to it's own window. I am thinking something like modal would be the answer. how?
Hi Stephanie! I'm a little rusty at Java. I haven't used the language in a few years. If I'm understanding right, a possible solution would be to create a separate class for each unique window that you would need. Then on the main window, have separate buttons that would call the constructor of each unique class. Then disable buttons if needed. Hopefully I understood the question correctly.
If you want to click the button only once then use the - button. setEnabled(false) in the actionPerformed method, then it grays out the button after performing the task once
@@BroCodez What language have you been using recently?
About 300 likes and 0 dislikes!!! wow
My window in windowbulder is distorted and idk how to fix it
the like ratio is impressive lol
how do I make a new window come up when a username and password is entered in and clicked on a log in button
Mandatory supportive comment for the algorithm. Keep scrolling...
how to open the new window on the same spot as the previous window in case you drag it?
You shouldnât be opening new windows. Instead donât add items to a JFramw directly. Add them to a JPanel and add the panel to the frame. Then you can swap panels
my mother was a window
3.4đ·ïžđ»đ°âŸïžđđ±
It doesnât work
>if you learnt something new
no i didnt.
Hi I have 2 windows and I want to be able to go back and forth to each other I can do the go to the second window part -thanks to you- but when I go back to the first window it duplicates.can you help?
Use 'setDispose()' on both frames.
420 lol
comment
wow 0 disslikes
COMMENT
package CodeBro;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ACTION_LISTENER_CLASS implements ActionListener {
int i =0;
static JFrame frame2;
String title ;
static JButton button =new JButton();
public static void main(String[] args) {
button.setBounds(200,200,200,200);
button.setText("new frame");
button.setFocusable(false);
button.addActionListener(new ACTION_LISTENER_CLASS());//to add action listener
JFrame frame = new JFrame("ACTION LISTENER CLASS AND MULTIPLE FILE AT SAME TIME");
frame.setBounds(0,0,800,800);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setLayout(null);
frame.add(button);
frame.setVisible(true);
frame2 = new JFrame();
frame2.setBounds(0,0,200,200);
frame2.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource()==button){
int z=i++;
title="frame"+i;
frame2.setTitle(title);
frame2.setVisible(true);
}
}
}
i know im a little late but on the label I put the text "You are dead" and it cut it off and said "you ar.." how I fix
Anyone know why "(JFrame.EXIT_ON CLOSE)" is throwing an error when I typed it exactly like he did and imported swing.JFrame ??
1.00000.MAS.PASS.1.11111
Thank you bro
Thanks