actionscript 3 creating an object with changing numbers at the end - actionscript-3

How do I create objects with the same base name such as employe but change the number at the end? I have the first 3 employees created but I'd like to be able to create other objects with employe but with different numbers at the end. Is that possible? If so would there be any good reason to do it? Or would it be better to just add the objects into the array without naming it?
This is my code.
package {
import flash.events.*;
import flash.display.*;
public class U2TF5_Employes extends MovieClip{
//Crée les premier 3 employes
var employe1: Object = new Object();
var employe2: Object = new Object();
var employe3: Object = new Object();
//Crée le tableay principal et un tableau avec les propriétés
var employees: Array = new Array();
var proprietes: Array = ["numero", "prenom", "nomDeFamille", "salaireAnnuel", "dateEmbauche"];
//Constructor code
public function U2TF5_Employes() {
btnAjouter.addEventListener(MouseEvent.CLICK, ajouter);
btnAfficher.addEventListener(MouseEvent.CLICK, afficher);
btnSupprimer.addEventListener(MouseEvent.CLICK, supprimer);
employe1 = {numero: 1, prenom: "Paul", nomDeFamille: "Breau", salaireAnnuel: 0.1, dateEmbauche: "16/02/29"};
employe2 = {numero: 2, prenom: "William", nomDeFamille: "Tam", salaireAnnuel: 10000000, dateEmbauche: "16/02/28"};
employe3 = {numero: 3, prenom: "Erica", nomDeFamille: "Bélanger", salaireAnnuel: 999999999, dateEmbauche: "05/09/12"};
employees.push(employe1);
employees.push(employe2);
employees.push(employe3);
}
private function ajouter(e: MouseEvent): void {
}
private function afficher(e: MouseEvent): void {
txtEmployes.text = "";
for (var i: int = 0; i < employees.length; i++) {
for each (var proprietesEmploye: String in proprietes) {
txtEmployes.appendText(proprietesEmploye + ": " + employees[i][proprietesEmploye] + "\n");
}
txtEmployes.appendText("\n");
}
}
private function supprimer(e: MouseEvent): void {
}
}
}

Yes, it's very possible to create more objects. One possibility is to update your class like this:
public class U2TF5_Employes extends MovieClip{
//Crée les premier 3 employes
var employe4: Object = new Object();
//Constructor code
public function U2TF5_Employes() {
//Add these lines to the end of the existing function
employe4 = {numero: 4, prenom: "Erica", nomDeFamille: "Bélanger", salaireAnnuel: 999999999, dateEmbauche: "05/09/12"};
employees.push(employe4);
}
}
Another option is to declare your additional objects and push them:
public function U2TF5_Employes() {
//Add these lines to the end of the existing function
var employeToAdd = {numero: 5, prenom: "Erica", nomDeFamille: "Bélanger", salaireAnnuel: 999999999, dateEmbauche: "05/09/12"};
employees.push(employeToAdd);
employeToAdd = {numero: 6, prenom: "Erica", nomDeFamille: "Bélanger", salaireAnnuel: 999999999, dateEmbauche: "05/09/12"};
employees.push(employeToAdd);
//etc
//or even:
employees.push({numero: 7, prenom: "Erica", nomDeFamille: "Bélanger", salaireAnnuel: 999999999, dateEmbauche: "05/09/12"});
}

Related

MVC+ SWING and a ListSelectionListener

What I am trying to do is get the selected value from my SWING View JList to my controller class, so I can use that data in my controller.
For simplicity I manually added 2 elements to my JList("Item 1", "Item 2", (so I have something to pass)I seem to have a problem accessing it. My View has a JList with a ListSelectionListener which I pass to my controller via my main:
public class AppMain {
private AppView appView = null;
public static void main(String[] args) {
AppView appView = new AppView();
Controller controller = new Controller(appView);
}
public AppView getView() {
return appView;
}
}
My view is:
import javax.swing.event.ListSelectionListener;
public class AppView extends javax.swing.JFrame {
public AppView() {
initComponents();
this.setVisible(true);
}
#SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
ValueList = new javax.swing.JList();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
ValueList.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "Item 1", "Item 2", " " };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
jScrollPane1.setViewportView(ValueList);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(75, 75, 75)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(63, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(45, 45, 45)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(27, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.JList ValueList;
private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration
public void ListSelectionListener(ListSelectionListener selectionListener) {
ValueList.addListSelectionListener(selectionListener);
}
}
And a Controller:
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
public class Controller implements ListSelectionListener{
AppView gui;
public Controller(AppView v)
{
gui = v;
gui.ListSelectionListener(this);
}
#Override
public void valueChanged(ListSelectionEvent e) {
this.gui.ListSelectionListener(this);
System.out.println("FOO");
}
}
No I want TO get the selectedValue in the Controller. I can't seem to grasp it. Also This prints Foo 3 times and I also cannot find out why.
Thanks in advance
As shown in How to Write a List Selection Listener more than one ListSelectionEvent may be generated as the user selects fist one entry and then another. Try checking when the selection is stable.
if (!e.getValueIsAdjusting()) {
// examine result
ListSelectionModel lsm = (ListSelectionModel)e.getSource();
int minIndex = lsm.getMinSelectionIndex();
int maxIndex = lsm.getMaxSelectionIndex();
…
}

Recieveing Error : undefined property bitmapfilter type AS3

I'm working on a tutorial for a pong clone and am currently trying to add a BevelFilter to a ball image. When I type in the code it returns an error saying
undefined property bitmapfilter type
I checked on live docs and it should be valid. I marked the line with two *'s
package
{
import flash.display.Sprite;
import flash.display.Graphics;
import flash.events.Event;
import flash.filters.BevelFilter;
import flash.filters.GlowFilter;
public class Ball extends Sprite
{
private const RADIUS:int = 12;
private const COLOR:uint = 0x01A6B2;
private const COLOR2:uint = 0x45FCFF;
** private const BEVEL:BevelFilter = new BevelFilter(4, 90, COLOR2, 1, COLOR2, 1, 10, 10, 1, 1, BitmapFilterType.Inner, true);
private const GLOW:GlowFilter = new GlowFilter(0xFFFFFF, .6, 0, 0, 5, 1, true);
public function Ball():void {
addEventListener(Event.ADDED_TO_STAGE, go);
}
private function go(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, go);
graphics.lineStyle(2, COLOR, 1);
graphics.beginFill(COLOR);
graphics.drawCircle(0, 0, RADIUS);
filters = [BEVEL, GLOW];
}
}
}
Thanks!
I use these on a regular basis. Your code should look like this...
private const BEVEL:BevelFilter = new BevelFilter(4, 90, COLOR2, 1, COLOR2, 1, 10, 10, 1, 1, "inner", true);
That second-to-last argument accepts a string.
Not sure why the docs represent it differently. This was off of the code hints for Adobe Flash CS6, and I know this should work.

Get data from two object in OOP AS3

I have a Car class like this
public class Car extends Sprite
{
private var car :Sprite;
private var buttonCar :Sprite;
private var _kmh :int;
public function Car()
{
makeCar();
makeButtonCar();
}
private function makeCar() : void
{
car = new Sprite();
car.graphics.beginFill(0x0000FF, 1);
car.graphics.drawRect(0, 0, 100, 50);
car.x = 100;
this.addChild(car);
}
private function makeButtonCar() : void
{
buttonCar = new Sprite();
buttonCar.graphics.beginFill(0xFF0000, 1);
buttonCar.graphics.drawCircle(0, 0, 25);
buttonCar.x = 300;
this.addChild(buttonCar);
buttonCar.addEventListener(MouseEvent.MOUSE_DOWN, KMH);
}
private function KMH(e:MouseEvent) : void
{
_kmh++;
trace("kmh: "+_kmh);
}
}
in the Main class I make newCar from Car class, newCar1 and newCar2.
public class OOPVariable extends Sprite
{
private var newCar1  :Car;
private var newCar2  :Car;
public function OOPVariable()
{
newCar1 = new Car();
addChild(newCar1);
newCar2 = new Car();
newCar2.y = 100; 
addChild(newCar2);
super();
}
}
I want get total of variable _kmh from all object newCar when one of the button from newCar clicked and mouse event still in Car class.
you could either do what Nathan said, or you can make your kmh variable public;
that way you can access it through a mouseEvent.
first, you'll have to import flash.utils.getQualifiedClassName.
then you can use a for() loop to get all of the cars on stage, and trace the total KMH.
// traces out the total KMH and num of cars on stage
// your car class should keep kmh updated
private function getTotalKMH(e:MouseEvent) :void
{
var totalCars:int = 0;
var KMH:int = 0;
for (var i:int = 0; i < stage.numChildren-1; i++)
{
if (getQualifiedClassName(e.currentTarget) == "Car")
{
++totalCars;
KMH += getChildByIndex(i).kmh; // ".kmh" is the variable in your car class
}
}
trace("Total Cars: " + totalCars + "\nTotal KMH: " + KMH);
}
of course, you can do more than just trace it.
you can pass it to a class scope variable or a function if you need to.
thanks all for your reply, I'm using custom event and dispatch event like what Nathan said :D
this is Main class, carListener method summing all kmh from all car when button car clicked
package
{
import flash.display.Sprite;
import support.CarEvent;
import support.CarObject;
public class OOPCar extends Sprite
{
private var newCar1 :CarObject;
private var newCar2 :CarObject;
private var totalKmh :int = 0;
private var currentName :String;
public function OOPCar()
{
newCar1 = new CarObject();
newCar1.name = "car1";
newCar1.setKmh(2);
addChild(newCar1);
newCar1.addEventListener(CarEvent.UPDATE, carListener);
newCar2 = new CarObject();
newCar2.name = "car2";
newCar2.setKmh(4);
addChild(newCar2);
newCar2.addEventListener(CarEvent.UPDATE, carListener);
newCar2.y = 100;
}
private function carListener(e:CarEvent) : void
{
trace("kmhCar: "+e.kmhCar);
totalKmh += e.kmhCar;
trace("totalKmh: "+totalKmh);
currentName = e.currentTarget.name;
}
}
}
class for make a car
package support
{
import flash.display.Sprite;
import flash.events.MouseEvent;
public class CarObject extends Sprite
{
private var car :Sprite;
private var buttonCar :Sprite;
private var _kmh :int;
public function CarObject()
{
makeCar();
makeButtonCar();
}
private function makeCar() : void
{
car = new Sprite();
car.graphics.beginFill(0x0000FF, 1);
car.graphics.drawRect(0, 0, 100, 50);
car.x = 100;
this.addChild(car);
}
private function makeButtonCar() : void
{
buttonCar = new Sprite();
buttonCar.graphics.beginFill(0xFF0000, 1);
buttonCar.graphics.drawCircle(0, 0, 25);
buttonCar.x = 300;
this.addChild(buttonCar);
buttonCar.addEventListener(MouseEvent.MOUSE_DOWN, update);
}
public function setKmh(kmh:int) : void
{
_kmh = kmh;
}
public function update(e:MouseEvent) : void
{
dispatchEvent(new CarEvent(CarEvent.UPDATE, true, false, _kmh));
}
}
}
and this is my custom event
package support
{
import flash.events.Event;
public class CarEvent extends Event
{
public static const UPDATE:String = "update";
public var kmhCar :int;
public function CarEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, kmhCar:int = 0)
{
super(type, bubbles, cancelable);
this.kmhCar = kmhCar;
}
public override function clone() : Event
{
return new CarEvent(type, bubbles, cancelable, kmhCar);
}
public override function toString():String
{
return formatToString("CarEvent", "type", "bubbles", "cancelable", "eventPhase", "kmhCar");
}
}
}

LoaderMax image resize

I am trying to load xml images using LoaderMax and resize them using LiquidArea. When I try to load in a different image with resize using next or thumbnails, I get a weird error I can't understand. I was not able to get help so I've come here. The error message and code can be seen below.
RangeError: Error #2006: The supplied index is out of bounds.
at flash.display::DisplayObjectContainer/addChildAt()
at com.greensock.layout::AutoFitArea/set preview()
at com.greensock.layout.core::LiquidData/refreshLevel()
at com.greensock.layout::LiquidStage/refreshLevels()
at com.greensock.layout.core::LiquidData$/addCacheData()
at com.greensock.layout::LiquidArea/pinCorners()
at com.greensock.layout::LiquidArea/autoPinCorners()
at com.greensock.layout::LiquidArea()
at Main/loadImage()
at Function/<anonymous>()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at com.greensock.core::TweenCore/complete()
at com.greensock::TweenMax/complete()
at com.greensock::TweenMax/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.DisplayObject;
import com.greensock.TweenMax;
import com.greensock.layout.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.XMLLoader;
import com.greensock.loading.LoaderMax;
import com.greensock.loading.ImageLoader;
import com.greensock.loading.data.ImageLoaderVars;
import com.greensock.loading.display.ContentDisplay;
public class Main extends MovieClip
{
private static const THUMB_WIDTH:Number = 100;
private static const THUMB_HEIGHT:Number = 64;
private static const IMAGE_WIDTH:Number = 550;
private static const IMAGE_HEIGHT:Number = 355;
private var ls:LiquidStage;
private var la:LiquidArea;
private var xImgList:XMLList;
public var arrowRight:MovieClip;
public var arrowLeft:MovieClip;
private var currentImage:String;
private var image:ImageLoader;
private var index:Number = 0;
public function Main()
{
// load in xml
var xPhotography:XMLLoader = new XMLLoader("assets/data.xml");
xPhotography.addEventListener( LoaderEvent.COMPLETE, xmlLoaded );
xPhotography.load();
arrowRight.alpha = arrowLeft.alpha = 0;
arrowRight.addEventListener(MouseEvent.ROLL_OVER, rollOverArrowHandler, false, 0, true);
arrowRight.addEventListener(MouseEvent.ROLL_OUT, rollOutArrowHandler, false, 0, true);
arrowRight.addEventListener( MouseEvent.CLICK, onArrowClick );
arrowLeft.addEventListener(MouseEvent.ROLL_OVER, rollOverArrowHandler, false, 0, true);
arrowLeft.addEventListener(MouseEvent.ROLL_OUT, rollOutArrowHandler, false, 0, true);
arrowLeft.addEventListener( MouseEvent.CLICK, onArrowClick );
}
private function xmlLoaded( e:LoaderEvent ):void
{
var xData:XML = e.target.content;// get copy of xml
xImgList = new XMLList(xData.image);// grabbing xml image nodes
loadImage( 0 );
}
// load in the image
private function loadImage( index: Number ):void
{
ls = new LiquidStage(this.stage,550,419);
la = new LiquidArea(imgContainer, 0, 0, 550, 419);
var file:String = xImgList[index]. # url;
var image:ImageLoader = new ImageLoader("assets/images/" + file, new ImageLoaderVars()
.container( imgContainer )
.x(0)
.y(0)
.alpha( 0 )
.width( IMAGE_WIDTH )
.height( IMAGE_HEIGHT )
.onComplete(completeHandler)
.scaleMode( "proportionalOutside" )
);
image.load();
la.attach(image.content, {scaleMode:ScaleMode.PROPORTIONAL_OUTSIDE, crop:true});
}
private function completeHandler(event:LoaderEvent):void
{
TweenMax.to(event.target.content, 1.5, {alpha:1});
}
private function rollOverArrowHandler(e:MouseEvent):void
{
TweenMax.to(e.currentTarget, 0.5, {alpha:1});
}
private function rollOutArrowHandler(e:MouseEvent):void
{
TweenMax.to(e.currentTarget, 0.5, {alpha:0});
}
private function onArrowClick( e:MouseEvent ):void
{
switch (e.target)
{
case arrowRight :
index++;
break;
case arrowLeft :
index--;
break;
}
if (index == xImgList.length())
{
index = 0;
} else if (index < 0)
{
index = xImgList.length() - 1;
}
checkOldImage( index );// needed to help loading times
}
private function checkOldImage( index:Number ):void
{
var oldClip:DisplayObject = imgContainer.getChildAt( 0 );
var nextIndex = index;
TweenMax.to( oldClip, .5, { autoAlpha: 0, onComplete: completeFadeHandler, onCompleteParams:[oldClip] } );
function completeFadeHandler(child:DisplayObject):void {
if (child.parent) {
child.parent.removeChild(child);
}
loadImage(nextIndex);
}
}
}
}

javax.swing: JEditorPane (html page) doesn't appear on main frame

class Browser has method getBrowserWindow() which returns JEditorPane(new URL("some URL")).
class MainForm calls new Browser().getBrowserWindow() and assigns it to another JEditorPane object.
editor = new Browser().getBrowserWindow();
scrollpane = new JScrollPane(editor);
Object editor.hashCode() is correct, so there's no doubt that i've got the right object.
Still, i can't see html page in the main frame.
P.S. i've tried creating instead of htmlpane simple JEditorPane filled with text only,
and this one i couldn't see neither.
P.P.S.
package faxutils;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
public class MainForm {
public MainForm() {
}
private static GeneralActions ga = new GeneralActions();
private static Arguments _args_for_Update;
private static String _Phone;
private static JTextField[] emails;
private static MyConstants c = new MyConstants();
private static JFrame frame = new JFrame("frame title");
private static JCheckBox c2 = new JCheckBox("SMS Notification");
private static JCheckBox c1 = new JCheckBox("PDF");
private static JCheckBox c3 = new JCheckBox("153");
private static JTextField textBox1 = new JTextField(20);
private static JTextField textBox2 = new JTextField(20);
private static JTextField textBox3 = new JTextField(20);
private static JTextField textBox4 = new JTextField(20);
private static JTextArea richText = new JTextArea();
private static JEditorPane log = new JEditorPane();
private static JScrollPane scrollp = new JScrollPane(richText);
private static JScrollPane scrollplog = new JScrollPane(log);
private static JPanel p1 = new JPanel();
private static JPanel p2 = new JPanel();
private static JLabel label3 = new JLabel("Send to:");
private static JLabel label2 = new JLabel("number");
private static JLabel label = new JLabel("Fax:");
private static JPanel p3 = new JPanel();
private static JButton button1 = new JButton("Search");
private static JButton button2 = new JButton("Save");
private static JButton button3 = new JButton("Send");
private static Component[] comp = new Component[]{c1, c2, c3, textBox2, textBox3, textBox3, textBox4, richText, log, button2, button3};
private static void createAndShowGUI() {
//Create and set up the window.
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Set up the content pane.
Container contentPane = frame.getContentPane();
SpringLayout layout1 = new SpringLayout();
SpringLayout layout2 = new SpringLayout();
SpringLayout layout3 = new SpringLayout();
SpringLayout frmlayout = new SpringLayout();
p1.setBorder(new TitledBorder("Search"));
p2.setBorder(new TitledBorder("Customer details"));
p3.setBorder(new TitledBorder("Send test fax"));
p1.setLayout(layout1);
p2.setLayout(layout2);
p3.setLayout(layout3);
frame.setLayout(frmlayout);
//Create and add the components to p1.
p1.add(label);
p1.add(textBox1);
p1.add(button1);
//Create and add the components to p2
p2.add(scrollp);
p2.add(textBox2);
p2.add(textBox3);
p2.add(textBox4);
p2.add(c1);
p2.add(c2);
p2.add(button2);
//Create and add the components to p3
p3.add(c3);
p3.add(label3);
p3.add(label2);
p3.add(button3);
p3.add(scrollplog);
//Add panels to frame
contentPane.add(p1);
contentPane.add(p2);
contentPane.add(p3);
//Layout1
//label
layout1.putConstraint(SpringLayout.WEST, label,
5,
SpringLayout.WEST, p1);
layout1.putConstraint(SpringLayout.NORTH, label,
5,
SpringLayout.NORTH, p1);
//textbox1
layout1.putConstraint(SpringLayout.WEST, textBox1,
30,
SpringLayout.WEST, label);
layout1.putConstraint(SpringLayout.NORTH, textBox1,
0,
SpringLayout.NORTH, label);
//button1
layout1.putConstraint(SpringLayout.WEST, button1,
230,
SpringLayout.WEST, textBox1);
layout1.putConstraint(SpringLayout.NORTH, button1,
-5,
SpringLayout.NORTH, textBox1);
//Layout2
//RICHTEXT
layout2.putConstraint(SpringLayout.WEST, scrollp, 5, SpringLayout.WEST, p2);
layout2.putConstraint(SpringLayout.NORTH, scrollp, 5, SpringLayout.NORTH, p2);
layout2.putConstraint(SpringLayout.EAST, scrollp, -5, SpringLayout.EAST, p2);
layout2.putConstraint(SpringLayout.SOUTH, scrollp, -150, SpringLayout.SOUTH, p2);
//TEXTBOX1,2,3
layout2.putConstraint(SpringLayout.WEST, textBox2, 140, SpringLayout.WEST, scrollp);
layout2.putConstraint(SpringLayout.NORTH, textBox2, 130, SpringLayout.NORTH, scrollp);
layout2.putConstraint(SpringLayout.WEST, textBox3, 0, SpringLayout.WEST, textBox2);
layout2.putConstraint(SpringLayout.NORTH, textBox3, 25, SpringLayout.NORTH, textBox2);
layout2.putConstraint(SpringLayout.WEST, textBox4, 0, SpringLayout.WEST, textBox3);
layout2.putConstraint(SpringLayout.NORTH, textBox4, 25, SpringLayout.NORTH, textBox3);
//CHECKBOXES
layout2.putConstraint(SpringLayout.WEST, c1, 0, SpringLayout.WEST, scrollp);
layout2.putConstraint(SpringLayout.NORTH, c1, 200, SpringLayout.NORTH, scrollp);
layout2.putConstraint(SpringLayout.WEST, c2, 0, SpringLayout.WEST, c1);
layout2.putConstraint(SpringLayout.NORTH, c2, 25, SpringLayout.NORTH, c1);
//BUTTON
layout2.putConstraint(SpringLayout.WEST, button2, 160, SpringLayout.WEST, textBox4);
layout2.putConstraint(SpringLayout.NORTH, button2, 25, SpringLayout.NORTH, textBox4);
//Layout3
//CHECKBOX3
layout3.putConstraint(SpringLayout.WEST, c3, 5, SpringLayout.WEST, p3);
layout3.putConstraint(SpringLayout.NORTH, c3, 5, SpringLayout.NORTH, p3);
//label3
layout3.putConstraint(SpringLayout.WEST, label3, 50, SpringLayout.WEST, c3);
layout3.putConstraint(SpringLayout.NORTH, label3, 4, SpringLayout.NORTH, c3);
// label2
layout3.putConstraint(SpringLayout.WEST, label2, 50, SpringLayout.WEST, label3);
layout3.putConstraint(SpringLayout.NORTH, label2, 0, SpringLayout.NORTH, label3);
//button3
layout3.putConstraint(SpringLayout.WEST, button3, 305, SpringLayout.WEST, p3);
layout3.putConstraint(SpringLayout.NORTH, button3, 0, SpringLayout.NORTH, p3);
//Browser
layout3.putConstraint(SpringLayout.WEST, scrollplog, 0, SpringLayout.WEST, c3);
layout3.putConstraint(SpringLayout.NORTH, scrollplog, 25, SpringLayout.NORTH, c3);
layout3.putConstraint(SpringLayout.EAST, scrollplog, 320, SpringLayout.EAST, c3);
layout3.putConstraint(SpringLayout.SOUTH, scrollplog, 140, SpringLayout.SOUTH, c3);
//FrameLayout
//p1
frmlayout.putConstraint(SpringLayout.WEST, p1,
5,
SpringLayout.WEST, frame);
frmlayout.putConstraint(SpringLayout.NORTH, p1,
5,
SpringLayout.NORTH, frame);
frmlayout.putConstraint(SpringLayout.EAST, p1,
380,
SpringLayout.EAST, frame);
frmlayout.putConstraint(SpringLayout.SOUTH, p1,
50,
SpringLayout.SOUTH, frame);
//p2
frmlayout.putConstraint(SpringLayout.WEST, p2,
5,
SpringLayout.WEST, frame);
frmlayout.putConstraint(SpringLayout.NORTH, p2,
75,
SpringLayout.NORTH, p1);
frmlayout.putConstraint(SpringLayout.EAST, p2,
380,
SpringLayout.EAST, frame);
frmlayout.putConstraint(SpringLayout.SOUTH, p2,
285,
SpringLayout.SOUTH, p1);
//p3
frmlayout.putConstraint(SpringLayout.WEST, p3,
5,
SpringLayout.WEST, frame);
frmlayout.putConstraint(SpringLayout.NORTH, p3,
285,
SpringLayout.NORTH, p2);
frmlayout.putConstraint(SpringLayout.EAST, p3,
380,
SpringLayout.EAST, frame);
frmlayout.putConstraint(SpringLayout.SOUTH, p3,
200,
SpringLayout.SOUTH, p2);
//Display the window.
frame.setSize(400, 600);
initialize();
// frame.pack();
frame.setVisible(true);
}
private static void setPanelsEnabled(boolean b) {
for (int i = 0; i < comp.length; i++)
comp[i].setEnabled(b);
}
private static void initialize() {
try {
emails = new JTextField[]{textBox2, textBox3, textBox4};
textBox1.requestFocus();
setPanelsEnabled(false);
richText.setEditable(false);
log.setEditable(false);
textBox1.setText("enter number here");
} catch (Exception ex) {
System.out.println(c.MSGBOX_EXCEPTION_TITLE + ": " + ex);
}
}
private static void button1_Click() {
try {
label2.setText(textBox1.getText());
_Phone = textBox1.getText();
_args_for_Update = ga.query1(_Phone, c1, c2);
if (_args_for_Update.getUserId() == 0) {
c1.setSelected(false);
c2.setSelected(false);
System.out.println(c.MSGBOX_SEARCH_STATUS_TITLE + ": " + c.MSGBOX_NO_USER_WAS_FOUND);
} else {
richText.setText(_args_for_Update.getUserInfo());
ga.query2(_args_for_Update);
_args_for_Update.setEmailsAmount(ga.fillEmails(_args_for_Update, emails));
}
boolean b = _args_for_Update.getUserId() > 0;
setPanelsEnabled(b);
c3.setSelected(false);
} catch (Exception ex) {
System.out.println(c.MSGBOX_EXCEPTION_TITLE + ": " + ex);
}
}
private static void button2_Click() {
try {
int saveOK = ga.SaveSettings(_args_for_Update, emails, c1, c2);
button1.doClick();
if (saveOK == c.USER_UPDATE_RESULT_0)
System.out.println(c.MSGBOX_EMAIL_CHANGES_STATUS_TITLE + ": " + c.MSGBOX_CANNOT_DELETE_MAIN_EMAIL);
else
System.out.println(c.MSGBOX_USER_STATUS_TITLE + ": " + c.MSGBOX_USER_WAS_SUCCESSFULLY_UPDATED);
} catch (Exception ex) {
System.out.println(c.MSGBOX_EXCEPTION_TITLE + ": " + ex);
}
}
private static void checkBox3_CheckedChanged() {
if (c3.isSelected())
label2.setText(c.FAX_PREFIX_153 + _Phone.substring(1));
else
label2.setText(_Phone);
}
private static void button3_Click() {
try {
// debugging
// log = new Browser().getBrowserWindow(String.format(c.SEND_FAX, ".com")); /////////
log = new JEditorPane(new URL(String.format(c.SEND_FAX, ".com")));
// System.out.println(log.getText());
p3.remove(scrollplog);
scrollplog = new JScrollPane(log); //////////
p3.add(scrollplog, layout3);
scrollplog.repaint();
System.out.println(c.MSGBOX_TEST_FAX_STATUS_TITLE + ": " + c.MSGBOX_FAX_SENDING_IN_PROGRESS);
} catch (Exception ex) {
System.out.println(c.MSGBOX_EXCEPTION_TITLE + ": " + ex);
}
}
public static void main(String[] args) {
try {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
button1_Click();
}
});
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
button2_Click();
}
});
c3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
checkBox3_CheckedChanged();
}
});
button3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
button3_Click();
}
});
createAndShowGUI();
}
});
} catch (Exception e) {
System.out.println(">:)" + e + ">:)");
}
}
}
Instantiation of a Swing component is not enough to display it. It has to be added to some sort of a container (JFrame, JPanel...). Same is valid for reinitialization. After having a component reinitialized the old version has to be removed from the container and the new one added.