//****************************************************************************** // Nuotaka.java: Applet // //****************************************************************************** import java.applet.*; import java.awt.*; import NuotakaFrame; import IDD_DIALOG1; //import com.ms.com.Variant; //============================================================================== // Main Class for applet Nuotaka // //============================================================================== public class Nuotaka extends Applet { // STANDALONE APPLICATION SUPPORT: // m_fStandAlone will be set to true if applet is run standalone //-------------------------------------------------------------------------- private boolean m_fStandAlone = false; private IDD_DIALOG1 ctrls; Calc clc = null; // STANDALONE APPLICATION SUPPORT // The main() method acts as the applet's entry point when it is run // as a standalone application. It is ignored if the applet is run from // within an HTML page. //-------------------------------------------------------------------------- public static void main(String args[]) { // Create Toplevel Window to contain applet Nuotaka //---------------------------------------------------------------------- NuotakaFrame frame = new NuotakaFrame("Nuotaka"); // Must show Frame before we size it so insets() will return valid values //---------------------------------------------------------------------- frame.show(); frame.hide(); frame.resize(frame.insets().left + frame.insets().right + 300, frame.insets().top + frame.insets().bottom + 440); // The following code starts the applet running within the frame window. // It also calls GetParameters() to retrieve parameter values from the // command line, and sets m_fStandAlone to true to prevent init() from // trying to get them from the HTML page. //---------------------------------------------------------------------- Nuotaka applet_Nuotaka = new Nuotaka(); frame.add("Center", applet_Nuotaka); applet_Nuotaka.m_fStandAlone = true; applet_Nuotaka.init(); applet_Nuotaka.start(); frame.show(); } // Nuotaka Class Constructor //-------------------------------------------------------------------------- public Nuotaka() { // TODO: Add constructor code here } // APPLET INFO SUPPORT: // The getAppletInfo() method returns a string describing the applet's // author, copyright date, or miscellaneous information. //-------------------------------------------------------------------------- public String getAppletInfo() { return "Name: Nuotaka\r\n" + "Author: Vidmantas Kajokas\r\n" + "Created with Microsoft Visual J++ Version 1.1"; } // The init() method is called by the AWT when an applet is first loaded or // reloaded. Override this method to perform whatever initialization your // applet needs, such as initializing data structures, loading images or // fonts, creating frame windows, setting the layout manager, or adding UI // components. //-------------------------------------------------------------------------- public void init() { // If you use a ResourceWizard-generated "control creator" class to // arrange controls in your applet, you may want to call its // CreateControls() method from within this method. Remove the following // call to resize() before adding the call to CreateControls(); // CreateControls() does its own resizing. //---------------------------------------------------------------------- resize(600, 440); ctrls = new IDD_DIALOG1 (this); ctrls.CreateControls(); InitControls(); // Graph ggg = new Graph(1.0,0,"aaaaaaaaaaaaa"); // ggg.show(); // TODO: Place additional initialization code here } // Place additional applet clean up code here. destroy() is called when // when you applet is terminating and being unloaded. //------------------------------------------------------------------------- public void destroy() { // TODO: Place applet cleanup code here } // Nuotaka Paint Handler //-------------------------------------------------------------------------- public void paint(Graphics g) { g.drawRect(0,0,290,475); g.drawRect(300,0,140,200); } // The start() method is called when the page containing the applet // first appears on the screen. The AppletWizard's initial implementation // of this method starts execution of the applet's thread. //-------------------------------------------------------------------------- public void start() { // TODO: Place additional applet start code here } // The stop() method is called when the page containing the applet is // no longer on the screen. The AppletWizard's initial implementation of // this method stops execution of the applet's thread. //-------------------------------------------------------------------------- public void stop() { } // MOUSE SUPPORT: // The mouseDown() method is called if the mouse button is pressed // while the mouse cursor is over the applet's portion of the screen. //-------------------------------------------------------------------------- public boolean mouseDown(Event evt, int x, int y) { // TODO: Place applet mouseDown code here // IDD_DIALOG1 ctrls = new IDD_DIALOG1 (this); // ctrls.CreateControls(); return true; } // MOUSE SUPPORT: // The mouseUp() method is called if the mouse button is released // while the mouse cursor is over the applet's portion of the screen. //-------------------------------------------------------------------------- public boolean mouseUp(Event evt, int x, int y) { // TODO: Place applet mouseUp code here return true; } public boolean handleEvent(Event event) { if (event.id == Event.ACTION_EVENT && event.target == ctrls.CalculateButton) { Calculate(); return true; } else if (event.id == Event.ACTION_EVENT && event.target == ctrls.GraphButton) { DrawGraphics(); return true; } else if (event.id == Event.ACTION_EVENT && (event.target == ctrls.AukstasPerc || event.target == ctrls.KambSkPerc || event.target == ctrls.VoniaPerc || event.target == ctrls.TelPerc || event.target == ctrls.IspPerc || event.target == ctrls.PercButton)) { RecalcPerc(); return true; } else if (event.id == Event.WINDOW_DESTROY) { System.exit(0); return true; } return super.handleEvent(event); } // TODO: Place additional applet code here public void RecalcPerc(){ ctrls.BendrasPerc.setText( String.valueOf( Integer.valueOf(ctrls.AukstasPerc.getText()).intValue()+ Integer.valueOf(ctrls.KambSkPerc.getText()).intValue() + Integer.valueOf(ctrls.VoniaPerc.getText()).intValue() + Integer.valueOf(ctrls.TelPerc.getText()).intValue() + Integer.valueOf(ctrls.IspPerc.getText()).intValue())); } public void InitControls(){ ctrls.AukstasPerc.setText("20"); ctrls.KambSkPerc.setText("20"); ctrls.VoniaPerc.setText("20"); ctrls.TelPerc.setText("20"); ctrls.IspPerc.setText("20"); ctrls.BendrasPerc.setText("100"); ctrls.A1Value.setText("5"); ctrls.A2Value.setText("5"); ctrls.A3Value.setText("5"); ctrls.A4Value.setText("5"); ctrls.K1Value.setText("5"); ctrls.K2Value.setText("5"); ctrls.K3Value.setText("5"); ctrls.K4Value.setText("5"); ctrls.PirkIsp.setText("0.01"); } public void Calculate(){ Flat Flats = new Flat(50);; Flats.Flats[0].SetData(13,9,3,1,1,3); Flats.Flats[1].SetData(5,2,1,0,0,3); Flats.Flats[2].SetData(12,4,2,1,1,5); Flats.Flats[3].SetData(3,2,4,1,1,8); Flats.Flats[4].SetData(5,5,3,1,1,4); Flats.Flats[5].SetData(12,2,3,1,0,6); Flats.Flats[6].SetData(12,8,2,0,1,7); Flats.Flats[7].SetData(4,4,2,0,1,6); Flats.Flats[8].SetData(5,5,3,1,1,9); Flats.Flats[9].SetData(5,2,1,0,1,6); Flats.Flats[10].SetData(5,1,2,1,1,3); Flats.Flats[11].SetData(4,2,3,1,1,5); Flats.Flats[12].SetData(5,2,1,0,1,9); Flats.Flats[13].SetData(5,5,1,1,1,7); Flats.Flats[14].SetData(2,1,2,0,0,6); Flats.Flats[15].SetData(4,2,2,0,1,6); Flats.Flats[16].SetData(5,1,4,0,1,8); Flats.Flats[17].SetData(4,2,4,1,1,5); Flats.Flats[18].SetData(5,1,3,1,1,7); Flats.Flats[19].SetData(5,4,3,1,1,6); Flats.Flats[20].SetData(5,5,1,1,1,3); Flats.Flats[21].SetData(5,5,1,1,1,8); Flats.Flats[22].SetData(9,7,4,1,1,4); Flats.Flats[23].SetData(4,4,2,0,1,7); Flats.Flats[24].SetData(9,6,2,1,1,9); Flats.Flats[25].SetData(9,8,3,1,1,5); Flats.Flats[26].SetData(12,5,2,1,1,6); Flats.Flats[27].SetData(5,3,2,1,1,7); Flats.Flats[28].SetData(5,5,2,1,1,6); Flats.Flats[29].SetData(5,4,1,0,0,4); Flats.Flats[30].SetData(3,3,4,1,1,8); Flats.Flats[31].SetData(9,8,3,1,1,4); Flats.Flats[32].SetData(5,3,2,0,1,8); Flats.Flats[33].SetData(3,1,2,1,0,7); Flats.Flats[34].SetData(13,4,3,1,1,8); Flats.Flats[35].SetData(5,5,3,1,1,7); Flats.Flats[36].SetData(9,5,3,1,1,6); Flats.Flats[37].SetData(2,1,2,0,0,8); Flats.Flats[38].SetData(3,2,2,1,0,7); Flats.Flats[39].SetData(5,2,2,0,1,7); Flats.Flats[40].SetData(5,4,2,1,1,7); Flats.Flats[41].SetData(4,4,4,1,1,8); Flats.Flats[42].SetData(3,1,4,1,1,8); Flats.Flats[43].SetData(5,1,4,1,1,6); Flats.Flats[44].SetData(5,1,3,1,1,7); Flats.Flats[45].SetData(5,4,3,1,1,8); Flats.Flats[46].SetData(5,1,2,1,1,4); Flats.Flats[47].SetData(5,1,2,1,1,8); Flats.Flats[48].SetData(4,3,2,0,0,7); Flats.Flats[49].SetData(5,1,3,1,0,6); Parms parameter = new Parms( Integer.valueOf(ctrls.AukstasPerc.getText()).intValue(), Integer.valueOf(ctrls.A1Value.getText()).intValue(), Integer.valueOf(ctrls.A2Value.getText()).intValue(), Integer.valueOf(ctrls.A3Value.getText()).intValue(), Integer.valueOf(ctrls.A4Value.getText()).intValue(), Integer.valueOf(ctrls.KambSkPerc.getText()).intValue(), Integer.valueOf(ctrls.K1Value.getText()).intValue(), Integer.valueOf(ctrls.K2Value.getText()).intValue(), Integer.valueOf(ctrls.K3Value.getText()).intValue(), Integer.valueOf(ctrls.K4Value.getText()).intValue(), Integer.valueOf(ctrls.VoniaPerc.getText()).intValue(), Integer.valueOf(ctrls.TelPerc.getText()).intValue(), Integer.valueOf(ctrls.IspPerc.getText()).intValue()); if (!parameter.checkParms()) return; double pirkIsp = Double.valueOf(ctrls.PirkIsp.getText()).doubleValue(); clc = new Calc(); clc.init(Flats.noOfFlats,pirkIsp,pirkIsp*2,Flats,parameter); clc.recalc_bride(true); clc.recalc_grooms(pirkIsp*3*3); int buyFlat = clc.matchmake(); ctrls.ats_1.setText(String.valueOf(buyFlat)); ctrls.ats_2.setText(String.valueOf(Flats.Flats[buyFlat].Floor)); ctrls.ats_3.setText(String.valueOf(Flats.Flats[buyFlat].RoomsCount)); if (Flats.Flats[buyFlat].Toilet == 1) ctrls.ats_4.setText("yra"); else ctrls.ats_4.setText("nera"); if (Flats.Flats[buyFlat].Telefon == 1) ctrls.ats_5.setText("yra"); else ctrls.ats_5.setText("nera"); ctrls.ats_6.setText(String.valueOf(Flats.Flats[buyFlat].Impression)); } public void DrawGraphics(){ double pirkIsp = Double.valueOf(ctrls.PirkIsp.getText()).doubleValue(); if (clc == null) return; double temp[] = new double[50]; Graph ggg = new Graph(pirkIsp*3*3,50,"No of flats.: "+50); clc.copy_groom_array(temp); ggg.setGroomData(temp); clc.copy_bride_array(temp); ggg.setBrideData(temp); clc.copy_bride_impr_array(temp); ggg.setBrideImpr(temp); ggg.setShowData(1,true,Color.black); ggg.setShowData(2,true,Color.red); ggg.setShowData(3,true,Color.blue); ggg.setShowData(4,true,Color.black); ggg.setShowData(5,true,Color.yellow); ggg.show(); } }