I am working with JFrame and observers. I have a functioning GUI with multiple buttons and functions.
I am trying to create a button which opens a new window, that is exactly the same as the main window. All changes in any window, should be automatically updated to all open windows.
Any help how to begin?
General suggestions:
Use Model-View-Control or MVC design pattern,
use a factory method to create your sub-views (or as you call them, windows), createWindow(Model model), and
give each sub-view the same shared model object.
Related
I'm looking for a program, application, or some way to examine a java application, and be able to view its GUI information. This would include buttons, labels, panels, and list information. Ideally you could examine things by using the mouse pointer, and either hovering over an object or clicking on it. The separate program or application could display things like type of object, object name, and position of object in a console or a window.
I've found some applications that can examine a java application if it's using the Java Access Bridge, but I'm looking for a way that does not require the target java application to have the JAB.
Java Native Interface (JNI) allows you to get mouse clicks, positioning, and keyboard presses, but it does not appear to return information, like button names, inside a java application. Any ideas?
Answers to this question will be highly subjective, depending on the type of GUI technology used and the personal views of the answering person.
That being said, when I do JavaFX development, I use ScenicView. It works really well in my experience and can be loaded a number of different ways. It has most of the features you mentioned and displays a ton of data about the GUI objects, as well as highlighting the selected object's boundaries.
I want to make all Windows open in a Java swing application sharing same language InputMethod, that is, changing InputMethod in one window will result InputMethod changing in every other Window.
I have tried to create a single global InputContext and override getInputContext() of each window to return that Context, but it's not working reliably for some language input methods. Any idea?
I have created some custom JPanel classes using the NetBeans GUI Builder. Next, I added them to the palette. Then I created a custom JFrame and was able to drag my JPanels onto the JFrame. This worked great while I was simply working on the GUI front end. Now I am working on the backend logic, which includes some JDBC code. I have created a BaseballCardIO interface and implemented it in BaseballCardJDBCIO to centralize all the the database stuff.
Now, one of my JPanels, AddCardsPanel, needs a reference to one of these BaseballCardIOs. I started by creating one directly in the AddCardsPanel constructor. (I know, not the best design decision anyway...) Everything was working great until I open my JFrame class in NetBeans. It started to complain about not finding the JDBC driver class.
I want to continue to use the NetBeans GUI Builder for now. I have two solutions in mind to fix my problem:
1) Tell NetBeans where to find the JDBC driver and keep the code as-is. How do I do this?
2) Modify my design so that AddCardsPanel has a constructor which takes a BaseballCardIO as a parameter. This would actually be preferrable since it makes more sense for someone else to be responsible for creating the BaseballCardIO, not AddCardsPanel. However, I still need AddCardsPanel to play nicely with NetBeans GUI Builder, which means that it needs a no-args constructor. I imagine that I could add some code which detects if AddCardsPanel is being used as a JavaBean by NetBeans then the JFrame calls the noargs constructor. Otherwise, if my application is actually running, then the JFrame calls other constructor and sends it a BaseballCardIO.
Is this a good way to go? Or does anyone have any other possible solutions?
Add the driver JAR to NetBeans as a library, shown here, and to your project, shown here.
In Window > Services > Database > New Connections, fill out the required fields.
Don't let the NetBeans GUI builder dictate your design. Isolate database access to your TableModel and other component models.
Edit your question to include an sscce that shows any problems you encounter; a .form should not be required.
I have a program that uses a JFrame. I would like to make it so people could play my game from a website. Is there an easy way to turn JFrames into JApplets?
I have a program that uses a jFrame. I would like to make it so people could play my game from a website. ..
Launch the JFrame directly off a web site using Java Web Start. JWS offers many neat features, like auto-update & desktop integration (menu items, desktop shortcut).
..Is there an easy way to turn jFrames into jApplets?
When it comes to applets, nothing is easy.
It is always a matter of dealing with how different (versions of different) browsers, on different (versions of different) OS, using different (versions of different) Java plug-ins interact with each other. And that can often be summed up as 'poorly'.
I think the best way is to code your application to be contained within a JPanel. Then in the main method create the JFrame and adds that JPanel to it. Likewise, you can create a JApplet that gets created and just add the JPanel. This way your Swing application will be generally agnostic with regards to the top-level container.
You can simply create a JFrame from the applet. This JFrame then is a new OS window, and not still embedded in your browser.
Our program shows an example of this (of both popping up an external JFrame (or JDialog) and having components inside the applet, actually). (No source available, though.)
If I have Java program and I need to alter it to an interface and include icons,
is there any easy I can do this and is there a good application that can help me to do it ?
or do I have to code it in myself?
Nop, /me thinks ur need 1337 mad Java programin' skillz!
Translation for the rest of the world: Sorry, you'll need to program in Java.
Added: Hey, what's with the downvotes? He started it! :P Besides - no matter if he wants to add or modify (the original text wasn't clear on this) the UI of a Java program, he will need to program in Java to bring his UI together with the code. There is no miracle tool that can allow you to draw an UI and it will suddenly do what you do.
Netbeans has a Swing GUI Builder. Quoting from their website. Let's hope this doesn't count has hidden advertising :)
Design Swing GUIs by dragging and
positioning GUI components from a
palette onto a canvas. The GUI builder
automatically takes care of the
correct spacing and alignment. Click
into JLabels, JButtons, ButtonGroups,
JTrees, JTextFields, ComboBoxes and
edit their properties directly in
place. You can use the GUI builder to
prototype GUIs right in front of
customers.
If you want to add a UI to your Java program there are tools to help you, such as the Swing GUI Builder inside of IntelliJ Idea. However, you're still going to have to write the appropriate code to hook into the UI.
It's just a website? Well depending on whether it uses CSS you might be able to just modify a .css file. This will only let you modify how the site looks as opposed to works.
See here for an example of how this technology works. However this depends on how css-dependent the website is and it's possible you may still run into some difficulties.
You want to use a Java framework to help you with the UI. For example, you can use JSF (Javaserver faces), which allows you to drag and drop components for a UI onto the site. Otherwise, you can use web programs such as Dreamweaver to design the UI, before coding the backend logic yourself in java.