To get right right to my question.
How do you carry out large-scale graphic projects. I have not done any major GUI projects in Java yet, but what I'm working on has become pretty fast and pretty big, and now I'm stuck in a huge pile of code that is really annoying and confusing.
Since I came from the field of web development, I use the framework of MVC, so I have 3 packages in my projects. A model where I store classes that interact with whit or db files. Views where I store my classes for forms or GUI and Controller packages where I save most of my logic.
I was told to separate my logic, as well as keep actions in one class and listeners in another class, but I have no idea how to relate all this.
So far, I have only 1 controller class, where I execute all the methods regarding what happens in the GUI after it is called.
package pft.controller; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JLabel; import javax.swing.JComboBox; import javax.swing.JTree; import java.awt.event.*; import javax.swing.JProgressBar; import pft.view.Invoke_GUI; import pft.model.Events; import pft.model.Parse; public class Tower_Controller { public Tower_Controller() { } //Global variables String isSelected = null; int hasModules = 0; int cap = 0; int cpu = 0; int shield = 0; int armor = 0; public void setName(String name){ this.isSelected = name; } public String getName(){ return this.isSelected; } public void setCap(int cap){ this.cap = cap; } public int getCap(){ return this.cap; } public void setCpu(int cpu){ this.cpu = cpu; } public int getCpu(){ return this.cpu; } public void setShield(int shield){ this.shield = shield; } public int getShield(){ return this.shield; } public void setArmor(int armor){ this.armor = armor; } public int getArmor(){ return this.armor; } public void invoke() throws IOException { Invoke_GUI runnable = new Invoke_GUI(); final JLabel tower_name = runnable.tower_name; final JComboBox tower_select = runnable.tower_select; final JTree module_browser = runnable.module_browser; final JTree selected_modules = runnable.selected_modules; final JProgressBar cap_bar = runnable.cap_bar; final JProgressBar cpu_bar = runnable.cpu_bar; final JLabel em_res = runnable.em; final JLabel th_res = runnable.thermic; final JLabel ki_res = runnable.kinetic; final JLabel ex_res = runnable.explosive; setTowerName(tower_name, tower_select); removeTower(tower_name); runnable.setVisible(true); } public void removeTower(final JLabel tower_name) { tower_name.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (hasModules == 1 & isSelected != null) { Events evt = new Events(); evt.towerHasModules(); } else if (isSelected == null) { } else { tower_name.setText("No Control Tower selected"); isSelected = null; } } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } }); } public void updateVariables(String name) throws IOException{ Parse tower = new Parse(); String data[] = tower.towerData(name); Integer x = Integer.valueOf(data[1]).intValue(); setCap(x); } public void setTowerName(final JLabel tower_name, final JComboBox tower_select) { tower_select.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (isSelected != null) { Events evt = new Events(); evt.towerSelected(isSelected); } else { tower_name.setText(tower_select.getSelectedItem().toString()); setName(tower_name.toString()); try { updateVariables(tower_name.toString()); } catch (IOException ex) { Logger.getLogger(Tower_Controller.class.getName()).log(Level.SEVERE, null, ex); } } } }); } }
There are many tutorials and examples on how to make a small, usually one Java GUI class, but there are no tutorials or examples on how to execute projects that are more than one class.
Thanks in advance for your help and advice.
java user-interface swing
Sterling duchess
source share