Codename one Layered Layout not fill the screen - layout

I implemented floating button with this thread : How to achieve Floating Action Button in Codenameone?
but I have an layout issue. THe content doesn want to fill the screen. Here the screenshot :
Here how I created the content :
final Container paneContainer = new Container(new LayeredLayout());
private Container getBottomContainer(Form parent) {
newsfeedContainer.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
newsfeedContainer.setScrollableY(true);
loadData();
newsfeedContainer.addPullToRefresh(new Runnable() {
public void run() {
loadData();
}
});
//newsfeedContainer.add(new Button("Button")).add(new Button("Button")).add(new Button("Button")).add(new Button("Button")).add(new Button("Button"));
return newsfeedContainer;
}
private Container getUpperContainer(Form par) {
FlowLayout flow = new FlowLayout(Component.RIGHT);
flow.setValign(Component.BOTTOM);
Container conUpper = new Container(flow);
Button plus = new Button();
FontImage.setMaterialIcon(plus, FontImage.MATERIAL_ADD, 5);
plus.addActionListener((ActionEvent evt) -> {
Form f = new PostComment().commentForm(parent);
f.getToolbar().setBackCommand(parent.getTitle(), BACK_POLICY, e -> parent.showBack());
f.show();
});
conUpper.addComponent(plus);
conUpper.setScrollableX(false);
conUpper.setScrollableY(false);
return conUpper;
}
public Container getContainer(Form parent) {
this.parent = parent;
paneContainer.setScrollableY(false);
paneContainer.addComponent(BorderLayout.center(getBottomContainer(parent)));
paneContainer.addComponent(BorderLayout.south(getUpperContainer(parent)));
return paneContainer;
}
How to make the container fill the screen and make the 'plus' button in the bottom right properly?

Make your Form BorderLayout and place the paneContainer in the center

Related

Drag text from browser into JavaFX GUI

I can't find any question exactly like this: Is there a way in JavaFX to display a GUI (stage) that accepts text that a user drap-and-drops from a browser?
For instance, the user navigates to a certain URL, then copies all of the page's text and drags it into the JavaFX stage displayed. The text can then be used within the Java program. I'd prefer not to use Selenium so that my app doesn't perform any scrape-like activities.
I'm looking for a solution compatible with Windows XP+ and all browsers.
Any feedback regarding starting points, tutorials, posts or limitations is great. Thank you
You may try something like this:
public class MainApp extends Application {
#Override
public void start(Stage stage) throws Exception {
TextField textField = new TextField();
textField.setPromptText("Drag text here");
textField.addEventHandler(
DragEvent.DRAG_OVER,
event -> {
if (event.getDragboard().hasString()) {
event.acceptTransferModes(TransferMode.COPY);
}
event.consume();
});
textField.addEventHandler(
DragEvent.DRAG_DROPPED,
event -> {
Dragboard dragboard = event.getDragboard();
if (event.getTransferMode() == TransferMode.COPY &&
dragboard.hasString()) {
textField.setText(dragboard.getString());
event.setDropCompleted(true);
}
event.consume();
});
StackPane stackPane = new StackPane(textField);
stackPane.setPadding(new Insets(5));
stage.setScene(new Scene(stackPane, 300, 150));
stage.setTitle("Drag and Drop");
stage.show();
}
public static void main(String[] args) {
MainApp.launch(args);
}
}
Getting HTML content
TextArea textArea = new TextArea();
textArea.setPromptText("Drag text here");
textArea.addEventHandler(
DragEvent.DRAG_OVER,
event -> {
if (event.getDragboard().hasHtml()) {
event.acceptTransferModes(TransferMode.COPY);
}
event.consume();
});
textArea.addEventHandler(
DragEvent.DRAG_DROPPED,
event -> {
Dragboard dragboard = event.getDragboard();
if (event.getTransferMode() == TransferMode.COPY &&
dragboard.hasHtml()) {
textArea.setText(dragboard.getHtml());
event.setDropCompleted(true);
}
event.consume();
});

How to open JavaFX browser in a separate thread

i have a simple JavaFx browser that is launched through a JButton that it's placed into a JFrame. Now, i wanted to put the JavaFx broser into a separate thread that should run even if the JFrame is closed. Now, if i close the JFrame with that JButton, the JavaFx browser also closes. I've tried multiple combinations, done research over internet, but with no success. Hope you guys can help me with a little example. Thanks !
browser.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(e.getSource() == browser) {
// create a JFXPanel, which will start the FX toolkit
// if it's not already started: - folosit pt a integra componente de tip FX Stage in componente swing (mai vechi) (JFrame)
JFXPanel fxPanel = new JFXPanel();
Platform.runLater(new Runnable() {
#Override
public void run() {
Scene scene;
TextField addressField;
WebView webView;
WebEngine webEngine;
Stage stage = null;
Button reloadButton, goButton, backButton , forwardButton, historyList;
HBox hBox = new HBox(5);
hBox.setAlignment(Pos.CENTER);
//The TextField for entering web addresses.
addressField = new TextField("Ionutz says: Enter the address here....");
addressField.setPrefColumnCount(50); //make the field at least 50 columns wide.
//Add all out navigation nodes to the vbox.
reloadButton = new Button("Reload page");
goButton = new Button("Search");
backButton = new Button("Back");
forwardButton = new Button("Forward");
historyList = new Button("History");
String urlSearch = "http://icons.iconarchive.com/icons/ampeross/qetto-2/24/search-icon.png";
String urlReload = "http://icons.iconarchive.com/icons/graphicloads/colorful-long-shadow/24/Arrow-reload-2-icon.png";
String URLBack = "http://icons.iconarchive.com/icons/custom-icon-design/flatastic-1/24/back-icon.png";
String URLForward = "http://icons.iconarchive.com/icons/custom-icon-design/flatastic-1/24/forward-icon.png";
String URLHistory = "http://icons.iconarchive.com/icons/delacro/id/24/History-icon.png";
goButton.setGraphic(new ImageView(urlSearch));
reloadButton.setGraphic(new ImageView(urlReload));
forwardButton.setGraphic(new ImageView(URLForward));
backButton.setGraphic(new ImageView(URLBack));
historyList.setGraphic(new ImageView(URLHistory));
hBox.getChildren().addAll(backButton, forwardButton, addressField, reloadButton, goButton, historyList);
//Our weiv that display ther page.
webView = new WebView();
//the engine that manages our pages.
webEngine = webView.getEngine();
webEngine.setJavaScriptEnabled(true);
webEngine.load("http://www.google.ro");
//our main app layout with 5 regions.
BorderPane root = new BorderPane();
root.setPrefSize(1280, 720);
//Add every node to the BorderPane.
root.setTop(hBox);
root.setCenter(webView);
//Our scene is where all the action in JavaFX happens. A scene holds all Nodes, and its root node is our BorderPane.
scene = new Scene(root);
//the stage manages the scene.
fxPanel.setScene(scene);
JFrame browserFrame = new JFrame();
browserFrame.add(fxPanel);
browserFrame.setTitle("Ionutz Asaftei Browser");
browserFrame.setBounds(200, 200, 1280, 720);
browserFrame.setVisible(true);
// adaugam event handlers !!!! - cele mai simple pt Buttons
reloadButton.setOnAction(new EventHandler<javafx.event.ActionEvent>() {
public void handle(javafx.event.ActionEvent event) {
webEngine.reload();
}
});
goButton.setOnAction(new EventHandler<javafx.event.ActionEvent>() {
public void handle(javafx.event.ActionEvent event) {
webEngine.load("http://"+addressField.getText());
}
});
forwardButton.setOnAction(new EventHandler<javafx.event.ActionEvent>() {
public void handle(javafx.event.ActionEvent event) {
webEngine.getHistory().go(1); //avanseaza cu o pagina in functie de intrarile din history
}
});
backButton.setOnAction(new EventHandler<javafx.event.ActionEvent>() {
public void handle(javafx.event.ActionEvent ev) {
webEngine.getHistory().go(-1); //merge in urma cu o pagina in functie de intrarile din history
}
});
}
});
}
}
});
The JavaFX toolkit is single threaded from a user application point of view. It is not possible to spawn multiple threads launching WebView instances.

UI Component [JavaFX Group] loses its position while the window is resized ... occurs only after scrolling horizontally

Please go through the image below.
In the above image you can find that horizontal scrolling is not started.
Now visit the After Scroll image of the same contents...
Now in the second image you can see that horizontal scrolling is done ...
JFXPanel contents are scroll horizontally... Which was perfect...
Now the third image will describe the problem....
It is liitle bit stretched to see as it is maximized...
You can see that the JFXPanel contents have changed their original position...
Moreover the contents must start with X_DisplaceMent = 0.0 [X-Cordinate], which was done automatically in the first two images...
All the contents are nodes like [Rectangle,Line etc.. ], after that all are placed in Group node...
And this Group node is set in the ScrollPane through
js.setContent(Group node);
Each component is placed with given x,y cordiante value .. then how did this happen while doing the maximized ?
Please help me to find the root cause ...
Thanks in advance...
Here are some facts that cause the problem.
- Start Position of Scene : 0.0
- Start Position of Group in Scene : 49.5
- Width of the root : 364.5
- Start Position of Scene : 0.0
- Start Position of Group in Scene : 63.5
- Width of the root : 364.5
- Start Position of Scene : 0.0
- Start Position of Group in Scene : 83.5
- Width of the root : 364.5
Whenever we drag the window horizontally Group is moving in the scene... That should not happen... how to avoid this ...
Ok... Here is the MCVE.....
There is a Frame. which contain SplitPane having vertical split.
The SplitPane will show the contents of two JFxPanels.
Both fxpanels are having rectangle on same x cordinate but Y cordinate is different.
And both the fxPanels are horizontal scroll sync. Not bi-directional. When you scroll lower panel horizonatally, the upper panel will get scrolled due to horizontal sync.
Here is the code for fxPanel 1...
public class FxPanel1 extends JFXPanel
{
private ScrollPane scroll ;
public ScrollPane getJs() {
return scroll;
}
public void setJs(ScrollPane js) {
this.scroll = js;
}
private boolean initFX(JFXPanel fxPanel) {
Scene scene = createScene();
fxPanel.setScene(scene);
return true;
//craneAssignmentChartView.setFxPanel(fxPanel);
}
private Scene createScene() {
Group root = new Group();
Rectangle rect = new Rectangle(10.0, 20.0, 800, 40);
rect.setFill(javafx.scene.paint.Color.TRANSPARENT);
rect.setStroke(javafx.scene.paint.Color.RED);
AnchorPane anchor = new AnchorPane();
anchor.getChildren().add(rect);
GridPane grid = new GridPane();
grid.setHgap(0);
grid.setVgap(0);
grid.setPadding(new Insets(0, 0, 0, 0));
grid.add(anchor, 1, 0);
root.getChildren().add(grid);
ScrollPane scroll = new ScrollPane();
scroll.setHbarPolicy(ScrollBarPolicy.ALWAYS);
scroll.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
scroll.setContent(root);
setJs(scroll);
return new Scene(scroll, javafx.scene.paint.Color.WHITE);
}
private void createUI(final JFXPanel fxPanel)
{
Platform.runLater(new Runnable() {
#Override
public void run()
{
initFX(fxPanel);
}
});
}
public FxPanel1( JFXPanel fxPanel)
{
createUI(fxPanel);
}
}
Now the code for second fxPanel looks like ...
public class FxPanel2 extends JFXPanel
{
private ScrollPane scroll ;
public ScrollPane getJs() {
return scroll;
}
public void setJs(ScrollPane js) {
this.scroll = js;
}
private boolean initFX(JFXPanel fxPanel) {
Scene scene = createScene();
fxPanel.setScene(scene);
return true;
//craneAssignmentChartView.setFxPanel(fxPanel);
}
private Scene createScene() {
Group root = new Group();
Rectangle rect = new Rectangle(10.0, 180.0, 800, 40);
rect.setFill(javafx.scene.paint.Color.TRANSPARENT);
rect.setStroke(javafx.scene.paint.Color.RED);
AnchorPane anchor = new AnchorPane();
anchor.getChildren().add(rect);
GridPane grid = new GridPane();
grid.setHgap(0);
grid.setVgap(0);
grid.setPadding(new Insets(0, 0, 0, 0));
grid.add(anchor, 1, 0);
root.getChildren().add(grid);
ScrollPane scroll = new ScrollPane();
scroll.setHbarPolicy(ScrollBarPolicy.ALWAYS);
scroll.setVbarPolicy(ScrollBarPolicy.NEVER);
scroll.setContent(root);
setJs(scroll);
return new Scene(scroll, javafx.scene.paint.Color.WHITE);
}
private void createUI(final JFXPanel fxPanel)
{
Platform.runLater(new Runnable() {
#Override
public void run()
{
initFX(fxPanel);
}
});
}
public FxPanel2( JFXPanel fxPanel)
{
createUI(fxPanel);
}
}
The main class looks like ....
public class DemoToCheckUIAlignment extends JFrame
{
public static void main(String[] args)
{
final DemoToCheckUIAlignment demo = new DemoToCheckUIAlignment();
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
JFXPanel panel1 = new JFXPanel();
FxPanel1 fxObj1 = new FxPanel1(panel1);
JFXPanel panel2 = new JFXPanel();
FxPanel2 fxObj2 = new FxPanel2(panel2);
DemoToCheckUIAlignment frame = new DemoToCheckUIAlignment();
frame.setSize(800, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JSplitPane chartSplitPane = new JSplitPane();
chartSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
chartSplitPane.setDividerLocation(200);
chartSplitPane.setDividerSize(2);
chartSplitPane.setTopComponent(panel1);
chartSplitPane.setBottomComponent(panel2);
demo.provideScrollSyncBetweenFXPanels(fxObj1.getJs(), fxObj2.getJs());
frame.getContentPane().add(chartSplitPane);
//frame.getContentPane().add(panel2);
frame.setVisible(true);
}
});
}
public static void provideScrollSyncBetweenFXPanels(final ScrollPane upperSP, final ScrollPane lowerSP)
{
lowerSP.hvalueProperty().addListener(new ChangeListener<Number>()
{
public void changed(ObservableValue<? extends Number> ov,
Number old_val, Number new_val)
{
upperSP.hvalueProperty().set(new_val.doubleValue());
}
});
}
}
Now to check the problem follow the simple steps...
Ofcorse run the program...
Scroll the bottom Panel ....that is FxPanel2...
And maximized the window .... The x - position for the inner contents is changed now...
which does not happen with Swing....
Here are the screen shots where the problem reproduce for the attached MCVE....Please go through the images....
You may use setFitToWidth of the ScrollPane Object to match a particular dimension. For more details you may refer to the link http://docs.oracle.com/javafx/2/ui_controls/scrollpane.htm at down the page, Resizing Components in the Scroll Pane, you may find more on the solution

LWUIT 1.5 How to capture tab click event, fetch content from server and show it in selected tab?

I am using LWUIT 1.5 tabs to show notifications. I have three Tabs and I fetch notifications from a php web service. I successfully fetched list of notifications for first Tab. But for next two Tabs I am failing to understand what code I should write to
Detect that second/third Tab is clicked. I know how to add commandListener to a Button. What commandListener is there for Tab selection?
How to refresh content of a Tab when new data is received from the server?
private void showNotificationList() {
try {
Form f = new Form("Notifications");
f.setScrollable(false);
f.setLayout(new BorderLayout());
final List list = new List(getNotifications()); //gets hashtables - notices
list.setRenderer(new GenericListCellRenderer(createGenericRendererContainer(), createGenericRendererContainer()));
list.setSmoothScrolling(true);
//System.out.println("adding list component to listview");
list.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
int i = list.getSelectedIndex();
noticeDetailsForm(notices[i]);
//Dialog. show( "title", notices[i].toString(), "ok", "exitt");
}
});
//Container c2 = new Container(new BoxLayout(BoxLayout.Y_AXIS));
//c2.addComponent(list);
Tabs tabs = new Tabs(Tabs.TOP);
tabs.addTab("Recent", list);
tabs.addTab("Urgent", new Label("urgent goes here"));
tabs.addTab("Favourites", new Label("favs goes here"));
//f.addComponent(tabs);
f.addComponent(BorderLayout.CENTER, tabs);
Command backComm = new Command("Back") {
public void actionPerformed(ActionEvent ev) {
Dashboard.dbInstance.setUpDashboard();
}
};
f.addCommand(backComm);
//System.out.println("showing lsit form");
f.show();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private Container createGenericRendererContainer() throws IOException { //System.out.println("container called");
//System.out.println("container called");
Container c = new Container(new BorderLayout());
c.setUIID("ListRenderer");
Label xname = new Label("");
Label description = new Label();
Label focus = new Label("");
Container cnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
xname.setName("Name");
xname.getStyle().setBgTransparency(0);
xname.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM));
//description.setFocusable(true);
description.setName("Description");
cnt.addComponent(xname);
cnt.addComponent(description);
c.addComponent(BorderLayout.CENTER, cnt);
Button thumb = new Button(Image.createImage("/res/home-work.png"));
//Image img = Image.createImage("/res/home-work.png");
c.addComponent(BorderLayout.WEST, thumb);
return c;
}
private Hashtable[] getNotifications() {
int total = notices.length;
//System.out.println(total);
Hashtable[] data = new Hashtable[total];
//Hashtable[] data = new Hashtable[5];
/data[0] = new Hashtable();
data[0].put("Name", "Shai");
data[0].put("Surname", "Almog");
data[0].put("Selected", Boolean.TRUE);/
for (int i = 0; i < total; i++) {
data[i] = new Hashtable();
//System.out.println(notices[i].getName());
data[i].put("Name", notices[i].getName());
data[i].put("Description", notices[i].getDescription());
data[i].put("Id", Integer.toString(notices[i].getId()));
}
return data;
}
1)I had the same problem and I solved it by overriding Keyreleased of the Form not the Tab
and inside it I check for the component that is focused and if it is the Tab get "tab.selectedIndex" to detect in which Tab I am and load appropriate data .
Here is Sample code(this inside the my derived form that extends Form )
**
public void keyReleased(int keyCode) {
Component p=this.getFocused();
String str= p.getClass().getName();
if(str.toLowerCase().indexOf("radiobutton")!=-1){ // Radiobutton because when u
Here do tab specific work focus on the
tab it returns radiobutton.
lwuit understands tabs as list
of radiobuttons
}**
2)and about refreshing the data I did a solution and I don't Know if its right
I get the new data , create new List and remove the old one and attach the new one then
call Form.repaint();

LWUIT: Need help `Back` command is not working properly

We show a SPLASH screen using form which is followed with MENU form that holds many buttons like about-us, login, feedback etc.
Now I move to LOGIN form that holds menu and back commands. My problem is when the back command is clicked in this form it goes to SPLASH screen.
The expected behavior is the back command in LOGIN form must go back to MENU form and not SPLASH form.
How to do this?
Splash.java
public class Splash extends MIDlet implements ActionListener {
Image img_Splash;
Form frm_Main;
String str_URL;
int Width, Height;
Label lbl_Splash;
Command cmd_Cancel;
public void startApp() {
Display.init(this);
frm_Main = new Form();
try {
//Resources theme = Resources.open("/44444.res");
img_Splash = Image.createImage("/res/splash.png");
Resources theme = Resources.open("/666666.res");
UIManager.getInstance().setThemeProps(
theme.getTheme(theme.getThemeResourceNames()[0]));
} catch (IOException io) {
io.printStackTrace();
Dialog.show("Theme Exception", io.getMessage(), "Ok", null);
}
lbl_Splash = new Label(img_Splash);
lbl_Splash.getStyle().setBgColor(16777215);
frm_Main.addComponent(lbl_Splash);
frm_Main.setScrollable(true);
cmd_Cancel = new Command("Cancel");
frm_Main.addCommand(cmd_Cancel);
frm_Main.addCommandListener(this);
frm_Main.show();
// th
Thread splashThread = new Thread() {
public void run() {
try {
sleep(5000);
} catch (InterruptedException ex) {
ex.printStackTrace();
} finally {
MainMenu mainmenu = new MainMenu(frm_Main);
mainmenu.show();
}
}
};
splashThread.start();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
//notifyDestroyed();
}
public void actionPerformed(ActionEvent ae) {
Command con = ae.getCommand();
String str_CmdName = con.getCommandName();
if (str_CmdName.equals("Cancel")) {
notifyDestroyed();
}
}
}
Mainmenu.java
class MainMenu extends Form implements ActionListener {
Form frm_Main;
//MainMidlet main;
public Button btn_main_Login, btn_main_NewUser, btn_main_Help;
public Label lbl_main_Login, lbl_main_NewUser, lbl_main_Help;
public Image img_main_Login, img_main_NewUser, img_main_Help;
public Command cmd_Exit, cmd_Select;
public MainMenu(Form form) {
this.frm_Main = form;
try {
img_main_Login = Image.createImage("/res/btn_main_login.png");
img_main_NewUser = Image.createImage("/res/btn_main_newuser.png");
img_main_Help = Image.createImage("/res/btn_main_help.png");
} catch (IOException io) {
io.printStackTrace();
//Dialog.show("Image not Found!", io.getMessage(), "Ok", null);
System.out.println("Image not found" + io.getMessage());
}
//--------- Whole form define as BorderLayout with three Container.
BorderLayout bor_MainMenuLayout = new BorderLayout();
setLayout(bor_MainMenuLayout);
setScrollable(false);
//----------- Define Container for Header On North
Container con_Header = new Container();
lbl_Header = new Label(img_Header);
con_Header.addComponent(lbl_Header);
//----------- Define Container as GridLayout and place
//----------- on BorderLayout Center position
//--------- Define Container(CENTER) for search details
//--------- with BoxLayout
BoxLayout bx_CenterLayout = new BoxLayout(BoxLayout.Y_AXIS);
Container con_Center = new Container(bx_CenterLayout);
con_Center.setScrollableY(true);
con_Center.getStyle().setPadding(0, 10, 3, 3);
//--------- FlowLayout for Header Details
FlowLayout flw_MenuHdr = new FlowLayout();
Container con_HdrDetails = new Container(flw_MenuHdr);
lbl_MenuHdr = new Label("Menu");
lbl_MenuHdr.getStyle().setBgTransparency(0);
lbl_MenuHdr.getStyle().setPadding(0, 5, 10, 0);
con_HdrDetails.addComponent(lbl_MenuHdr);
con_Center.addComponent(con_HdrDetails);
//---------- GridLayout define 1 rows and 3 coloumn
//---------- First row
GridLayout grd_Row1Layout = new GridLayout(1, 3);
Container con_Row1Layout = new Container(grd_Row1Layout);
btn_main_Login = new Button(img_main_Login);
btn_main_Help = new Button(img_main_Help;
btn_main_NewUser = new Button(img_main_NewUser);
con_Row1Layout.addComponent(btn_main_Login);
con_Row1Layout.addComponent(btn_main_Help);
con_Row1Layout.addComponent(btn_main_NewUser);
con_Center.addComponent(con_Row1Layout);
//----------- Add Command on softkey
cmd_Exit = new Command("Exit");
cmd_Select = new Command("Select");
addCommand(cmd_Select);
addCommand(cmd_Exit);
addCommandListener(this);
addComponent(BorderLayout.NORTH, con_Header);
addComponent(BorderLayout.CENTER, con_Center);
//this.getStyle().setBgColor(12105912);
frm_Main.getStyle().setBgColor(12105912);
}
public void actionPerformed(ActionEvent ae) {
Command cmd = ae.getCommand();
String str_CmdName = cmd.getCommandName();
//----------- When Click on Exit Button
if (str_CmdName.equals("Exit")) {
//System.exit(0);
//frm_Main.notifyAll();
}
//----------- When Click on Select Button
if (str_CmdName.equals("Select")) {
//----------- When Click on Login
if (btn_main_Login.hasFocus()) {
String str_MemberId = GlobalClass.getInstance().getMemberId();
if (!(str_MemberId == "" || str_MemberId == null)) {
SearchDiamond searchdiamond = new SearchDiamond(frm_Main);
searchdiamond.setTransitionInAnimator(
Transition3D.createRotation(800, true));
searchdiamond.show();
} else {
Login login = new Login(frm_Main);
login.setTransitionInAnimator(
Transition3D.createRotation(800, true));
login.show();
}
}
//----------- When Click on New User
if (btn_main_NewUser.hasFocus()) {
//Dialog.show("New User", "NewUser", "Ok", null);
NewUser newuser = new NewUser(frm_Main);
//newuser.setTransitionInAnimator(
CommonTransitions.createFade(1500));
newuser.setTransitionInAnimator(
Transition3D.createRotation(800, true));
newuser.show();
}
//----------- When Click on Help
if (btn_main_Help.hasFocus()) {
Help help = new Help(frm_Main);
help.setTransitionInAnimator(
Transition3D.createRotation(800, true));
help.show();
}
//----------- When Click on Exit
if (btn_main_Exit.hasFocus()) {
System.exit(0);
}
}
}
}
Login.java
class Login extends Form implements ActionListener {
Form frm_Main;
Label lbl_Header, lbl_Footer, lbl_SepLine, lbl_HdrAlreadyMember, lbl_UserID, lbl_PWD,
lbl_Blank2, lbl_Blank3, lbl_HdrNewMember, lbl_Info;
TextField txtf_UserID, txtf_PWD;
Button btn_Login;
Command cmd_Back, cmd_AboutUs, cmd_Privacy;
public Login(Form form) {
this.frm_Main = form;
//--------- Whole form define as BorderLayout with three Container.
BorderLayout bor_LoginLayout = new BorderLayout();
setLayout(bor_LoginLayout);
setScrollable(false);
//--------- Define Container(NORTH) for Header.
Container con_Header = new Container();
lbl_Header = new Label();
con_Header.addComponent(lbl_Header);
//--------- Define Container(CENTER) for search details
//--------- with BoxLayout
BoxLayout bx_CenterLayout = new BoxLayout(BoxLayout.Y_AXIS);
Container con_Center = new Container(bx_CenterLayout);
con_Center.setScrollableY(true);
con_Center.getStyle().setMargin(5, 5, 0, 0);
//--------- FlowLayout for Header Details
FlowLayout flw_HdrLayout = new FlowLayout();
Container con_HdrDetails = new Container(flw_HdrLayout);
lbl_HdrAlreadyMember = new Label("Already a Member?");
lbl_HdrAlreadyMember.setAlignment(Component.LEFT);
con_HdrDetails.addComponent(lbl_HdrAlreadyMember);
con_Center.addComponent(con_HdrDetails);
//--------- BoxLayout for Login details
BoxLayout bx_Login1Layout = new BoxLayout(BoxLayout.Y_AXIS);
Container con_Login1Details = new Container(bx_Login1Layout);
con_Login1Details.setScrollableY(true);
lbl_UserID = new Label("User Name:");
txtf_UserID = new TextField("");
txtf_UserID.setFocusable(true);
txtf_UserID.setFocus(true);
txtf_UserID.setConstraint(TextField.ANY);
txtf_UserID.setInputMode("abc");
lbl_PWD = new Label("Password:");
txtf_PWD = new TextField("");
txtf_PWD.setConstraint(TextField.PASSWORD);
con_Login1Details.addComponent(lbl_UserID);
con_Login1Details.addComponent(txtf_UserID);
con_Login1Details.addComponent(lbl_PWD);
con_Login1Details.addComponent(txtf_PWD);
//--------- BoxLayout for Login Button
FlowLayout flw_LoginBtnLayout = new FlowLayout(CENTER);
Container con_LoginBtnDetails = new Container(
flw_LoginBtnLayout);
con_LoginBtnDetails.setScrollableY(true);
btn_Login = new Button("Login");
btn_Login.setPreferredSize(new Dimension(80, 25));
btn_Login.setAlignment(Component.CENTER);
con_LoginBtnDetails.addComponent(btn_Login);
con_Login1Details.addComponent(con_LoginBtnDetails);
con_Center.addComponent(con_Login1Details);
//--------- BoxLayout for other Login details
BoxLayout bx_Login2Layout = new BoxLayout(BoxLayout.Y_AXIS);
Container con_Login2Details = new Container(bx_Login2Layout);
con_Login2Details.setScrollableY(true);
con_Login2Details.getStyle().setMargin(5, 5, 10, 10);
//--------- Login type 3 New Remember Me
chk_RememberMe = new CheckBox("Remember Me");
chk_RememberMe.setTickerEnabled(false);
con_Login2Details.addComponent(chk_RememberMe);
//--------- Login type 3 New Forgot Password
btn_ForgotPWD = new Button("Forgot Password?");
btn_ForgotPWD.setTickerEnabled(false);
btn_ForgotPWD.setAlignment(Component.LEFT);
btn_ForgotPWD.setTextPosition(Component.RIGHT);
con_Login2Details.addComponent(btn_ForgotPWD);
con_Center.addComponent(con_Login2Details);
con_Center.getStyle().setPadding(0, 0, 10, 10);
addComponent(BorderLayout.NORTH, con_Header);
addComponent(BorderLayout.CENTER, con_Center);
cmd_Back = new Command("Back");
this.setBackCommand(cmd_Back);
addCommand(cmd_Back);
addCommandListener(this);
//---------- Add More Command for Menu item
cmd_AboutUs = new Command("About Us");
cmd_Privacy = new Command("Privacy");
addCommand(cmd_AboutUs);
addCommand(cmd_Privacy);
//------- When Login Button is Clicked
btn_Login.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
....
}
});
}
public void actionPerformed(ActionEvent ae) {
Command con = ae.getCommand();
String str_CmdName = con.getCommandName();
if (str_CmdName.equals("Back")) {
// here back code
frm_Main.setTransitionInAnimator(
Transition3D.createRotation(800, true));
frm_Main.showBack();
}
....
if (str_CmdName.equals("About Us")) {
AboutUs aboutus = new AboutUs(frm_Main);
aboutus.show();
}
if (str_CmdName.equals("Privacy")) {
Privacy privacy = new Privacy(frm_Main);
privacy.show();
}
}
}
EDIT: Added the form's source code
Got it!
In MainMenu(...) constructor you are storing the reference of SPLASH screen in the class variable frm_Main, this class variable you are passing to the Login(...) constructor in the MainMenu.actionPerformed(...) so effectively you are passing the reference of Splash form object. You need to pass the current class which is MainMenu's reference to the Login(...) constructor and NOT the MainMenu.frm_Main.
Do this, if you don't expect to get back to the Splash screen from MainMenu screen:
public MainMenu(Form form)
{
this.frm_Main = this; //by referring to `MainMenu.this` and not input
//parameter `form` which is referring to Splash
//object
...
If you want to maintain the back reference for MainMenu screen than do this in MainMenu.actionPerformed(...)
Login login = new Login(/*global variable for `MainMenu.this`*/);

Resources