design - Java Architecture - Question about ActionListener Conventions -
I am creating a user interface that shows the graph and combines the graph I class applied JFrame ActionListener applies The functionalist then calls different classes to manipulate the graph on the basis of action. While doing this, there were some executiveists in the classroom; However, the class is now becoming unmanaged.
I know that in the interest of encapsulation, the action listener must be best done within the user interface class because it needs access to non-fixed components of the interface. However, it seems that there is a conflict between encapsulation and readability.
Am I breaking the class in the classroom for the interface and I am proposing to access the second and the interface components for ActionListener? Would I want to know that this basic design conventions Adhere? And, if this is an acceptable approach, will you keep the main category in the user-interface class or the action listener class?
.
Brief summary, JFRM Class will not have implemented the ActionListener for my priority, and after that there will be many names inner classes with JFrame which implement ActionListener.
I keep myself the main place in a class ... and it is called Maine.
The way I want to do it, here is some sample code:
import javax.swing.JFrame; Import javax.swing.SwingUtilities; Public Class Main {Private Main ()} {Public Public Zero Main (String [] Args) {SwingUtilities.invokeLater (New Runnab) (Public Running Zero () {createAndShowGUI ();}}); } Private static empty null and shoogui () {final fro frame; Frame = new FooFrame (); Frame.setupGUI (); Frame.pack (); Frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Frame.setVisible (true); }}
and then the GUI:
import java.awt.FlowLayout; Import java.awt.LayoutManager; Import java.awt.event.ActionEvent; Import java.awt.event.ActionListener; Import javax.swing.JButton; Import javax.swing.JFrame; Public Square FooFrame JFrame {Personal Finals JButton Rise BTN; Personal Finals Jebton Fall BTN; Private int values; {IncrementBtn = New Payton ("++"); Decrease BTN = new pocket ("-"); } Private Class Animation Listener Action Lastener {Public Zero Action Perfid (Last Action Event Evert) {increment (); }} Implementation of Private Class DecrementListener ActionListener {Executed Public Zero Action (Last ActionEvent evt) {Deficiency (); }} Public Zero Setup GUI () {Final Layout Manager Layout; Layout = new flow layout (); SetLayout (layout); SetupListeners (); AddComponents (); } Private Zero Setup Listener () {incrementBtn.addActionListener (new enhancement listener); Subtraction BBn.addActionListener (New DecrementListener ()); } Private Zero addComponents () {add (increase BTN); Add (decrementBtn); } Private Zero Wage () {value ++; System.out.println ("value =" + value); } Private Zero reduction () {value--; System.out.println ("value =" + value); }}
Comments
Post a Comment