• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Need to convert console code to jframe

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I'm trying to convert my console code into Jframe but I can't figure out how to. Can someone help me out I'd really appreciate it!


 
Saloon Keeper
Posts: 3415
149
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Jedda,

welcome to the Ranch and enjoy the stay!

Looking at your code, the simplest way I can think of is:

If you have an IDE, use its GUI Builder to create a JPanel that contains two JButtons called, for instance:
Select Docx file, Select xml file
with a JTextField to the right of each Button to show the file selected.

Add to each button an ActionListener that opens a JFileChooser, that lets you choose a file.

Add a JLabel that shows status reports.

Then, a JButton "Process" with an ActionListener that, when clicked, starts the process. When that process has finished, set the JLabel text to "Saved as " + name of the outputfile.

Beware though: if that process takes more than a fraction of a second, let a SwingWorker execute that process.

 
Jedda Smith
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello @Piet Souris,
I tried my best to do the JfileChooser but I can't figure out how to do the process button with save
I'm new to Java and Swing so maybe I did some rookie mistakes you could help me out with. Thanks in advance!

 
Piet Souris
Saloon Keeper
Posts: 3415
149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Jedda,

well, it certainly looks nice and simple. A few remarks:

1. In your actionListener of the DOCX fileChooser, you show all present files to the user, including all files that are NOT of type DOCX. So, I would suggest to change the code slightly, as in:

2. And likewise for the XML filechooser.

3. I don't know how often files will be selected, but if that is more than once, then it makes sense to make the fileChoosers member fields, for instance xmlChooser and docChooser. You can directly call these from the actionListener, preventing the creation of new JFileChoosers whenever the browse button is clicked.
Another advantage is that such member choosers remember the last directory visited, and will start in that same directory next time they are used.

4. I am not sure what good are the static Strings that you define. In this line in "main" I see this:

That will be

That doesn't make sense.
I think a better way would be to create two extra member fields of type File, and maybe called docInput and xmlInput.
In your actionListeners you can then simpley say:

or

In the btnRun actionListener you can put something like:

So far my firt remarks. Let me know if there is something not clear, or where you may have other thoughts.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!