How does a JApplet Form communication with Servlet? - java

I'm working on a JApplet form to create lesson plans.
Administrator only can edit lesson plan ( add, edit, delete ).
I used JApplet Form in netbeans, and I added Table control.
Function ADD:
Administrator can select for example 2 cells and click button "Add lesson", then the add form will be visible.
How can I make it so that two cells will link together in one?
It's the same with delete lesson from table. How do I delete an entire row?
The administrator needs to somehow log in and after the Servlet authenticates the user he can save the lessons (or delete or modify) server-side. Is there a standard way to handle communication between an Applet and a Servlet?

In answer to the first part "how can I make it so that two cells will link together?" on easy solution is with JPanel.
Rather than adding two text fields to your form, add a JPanel and then place the two text fields within the JPanel. We can now remove or add this JPanel to the form programmatically. Going further, we could write another class that extends JPanel that includes these two text fields along with whatever additional functionality we need with them.

Related

Creating a Browse panel ( JPanel) for eCommerce items and adding them to a cart (another JPanel)

I am creating this movie rental app and I have to have a panel where you can see available movies either all of them or filter them through categories or search them by name.
Then the user has to be able to add them into their cart to check them out.
Now, for the first step, I don't know what component to use to make these actions possible. I thought of using one button(add button), one label(title) and one image(poster of the movie) and a textArea (description) for each movie but then I dont know how to make them searchable or filter them.
Now my guess is, there should be some component that could provide some of these properties already or there should be another combination of the components to achieve this task, but again I cannot think of anything else.

How to implement codes in GUI formed apps in Java swing?

I really have a hard time finding help on internet since no one is giving examples on how to implement codes in GUI formed app. So I have my interface created and whole app works through buttons. Every code I find is for just workspace line, or how would I call it. Now I want do the following:
I have an input page for registering members in the gym. When I register them, they go to jTable. Now, I want to make it possible to edit columns Weight and Instructor from the table. I saw how to add ComboBox into table column, but don't know how do it in GUI formed app, where table is not created by the code. And I want to edit Weight column with jTextField the same I would do with ComboBox for instructors.
The question can also be: How do I define these custom things in table (or any other object in GUI Java App) when I already have GUI table set on place with drag and drop in NetBeans?

Swing (Java) Category List

everyone.
I'm currently working on a project which is written in Java. As one of my features I want the application to display List of workout plans that are saved in the databases. Furthermore, I want the user to be able to click on particular instance of the workout Plan so that new JFrame is opened with further details which will be populated from the database.
You can see what I mean in the picture below, this is how I want my list to look like.
For this application I'm using Swing components to model my GUI. Its very important for me that those items within a list will act as a button so that you can open up new JFrame, but at the same time the content must be populated from database. Also when a new Workout Plan is added to the database the list must be updated and the item that will be added to that list has to be of the same format.
My question is whether it's possible to design that kind of list using Swing components, and if it is how would you do it.
Any suggestions or help will be appreciated.
I'm not that familiar with swing but, I think you can set your panel into a grid layout. Then divide the grid layout so that there are, for example, 10 rows and 1 column. Afterwards, fill the grid layout with JButton's. Whenever a button is pressed, it will open up a JFrame.
I feel like there's a better way to do this though.

HTML gallery page in Swing with drag-drop functionality

I was asked to write a JDialog separated into left and right panel. The left panel shows a demo HTML template gallery (small sized), and right panel shows series or list of images. I want to make it such that I can drag image on the list and place it on the gallery (or maybe drag out some image from the gallery). The problem is I don't know where to start with this, can anybody give me some idea?
An HTML gallery typically uses JS to do the 'heavy lifting' (I'm guessing it will require a slideshow as well). While Swing components support HTML (to an extent) they do not support JS.
I recommend not trying to render the HTML/JS in the GUI, instead, provide a JList in the GUI of the image+name objects chosen by the user (using JFileChooser). When each image is selected, you can show the 'preferred name' in a JTextField that allows the user to edit it.
Image order can be shown by the order in the list. To change the order, implement Drag'n'Drop. See the Drag and Drop and Data Transfer lesson for more details.
You will probably need a JLabel in the CENTER of the GUI to display the (full size) selected image, and show the order & timing of the slideshow.
Once the user is happy with the image selections, the order, the names & timing. Offer them a button to write all the details to a single directory including the HTML, script & images (easier). Once the HTML is written, invoke Desktop.open(File) to display the finished product to the user.
As to how you do all that, it is really beyond the scope of an answer on SO. You would need to do the tutorial on each part, and come back with more specific questions.

JTable that can save to a file

Does anyone know of a JTable based Swing component OR code example that can save to a file? i.e: provides a menu item or button that when clicked on prompts the user for a file location and saves the table's contents to a file (CSV, XLS, TXT, or whatever).
The easy part is looping through the rows and saving to a file. But there also needs to be a UI component ON the table itself that allows the user to initiate the save.
Write your own. All you do is use the table.getModel().getValueAt(...) method and loop through the rows and columns and then write the data to a file.
I have implemented this using the following approach:
Create an Action implementation: DelimitedExportAction. I typically add this action to a JToolBar, JMenuBar or JPopupMenu.
Expose a method void registerTable(JTable tbl). Internally this method adds a FocusListener to the JTable. When a given JTable gains focus set the tableToExport instance variable and enable the action.
When the actionPerformed(ActionEvent) method is called, invoke your export logic if tableToExport != null.
Rather than iterate over the TableModel I recommend iterating over the JTable, and for each row calling getValueAt(int, int) on the underlying TableModel, remembering to convert between view and model row / column indices. This is more intuitive to the end user as it means any sorting and filtering applied to the JTable is preserved during the export. (In my implementation I actually offer users the choice of exporting all data or visible data.)
Define a DelimitedExportFormatter whose role is to convert each object returned by getValueAt(int, int) to a String. Similar to when providing renderers to a JTable this class should permit you to provide a Format for a given Class or specific column, whereby a column specific format takes precedence. The default format applied to all other values should be: value == null ? "" : value.toString().
I allow the action to be configured in different modes (which also governs the action's icon):
Export to file: Launches a file chooser dialog allowing user to specify save destination.
Export to Excel: Saves the exported data as a temporary file and opens it within Excel.
Configurable export: Launches a dialog whereby the user can specify: row delimiter, field delimiter, columns to export, rows to export (all, visible, selected), save destination (Excel / File).
I'm afraid I can't provide the code as it is proprietary but hopefully this will put you on the right track. Good luck!
I recently created a very simple tutorial that exports data from JTable into excel file, using Tab-Separated Values(TSV) format. The application provides an Export button, which then triggers a dialog box (JFileChooser) to assist the user in specifying the file location/destination. I hope this helps somehow.
https://sites.google.com/site/teachmemrxymon/java/export-records-from-jtable-to-ms-excel
I don't know of any JTable-like Swing component that fulfills this exact need.
However, where would you expect the button to be placed on the table? In my opinion you would be better served by either adding the JTable to a JScrollPane and putting your "save" button on the JScrollPane or adding the JScrollPane to a JPanel and putting the "save" button on the JPanel. I don't see the logic behind having a button on the JTable itself.
If you want a menu item, you'd probably want to create the menubar and add the JTable to whatever container is holding the menubar. There's still no adding of a button to the table itself, mind you, but it would be the same thing visually.

Categories

Resources