I'm new to Symbian mobile app development. I'm currently developing an app using j2me/java me easyeclipse. I'm having a problem in the tabbedpane widget. I've already installed all the required library but it is not running because of the error "TabbedPane is deprecated".
Here is my code:
public void startApp() {
//init the LWUIT display
Display.init(this);
//setting the application theme
try{
Resources r=Resources.open("/LWUITtheme.res");
UIManager.getInstance()
.setThemeProps(r.getTheme
(r.getThemeResourceNames()[0]));
}catch (Exception e){}
Form mainForm = new Form("TabbedPane Demo");
mainForm.setLayout(new BorderLayout());
TabbedPane tabbedPane=new TabbedPane(TabbedPane.TOP);
tabbedPane.addTab("Tab 1", new Label("First Tab"));
tabbedPane.addTab("Tab 2", new Label("Second Tab"));
tabbedPane.addTab("Tab 3", new Label("Third Tab"));
tabbedPane.addTab("Tab 4", new Label("Fourth Tab"));
mainForm.addComponent(BorderLayout.CENTER, tabbedPane);
mainForm.setTransitionOutAnimator(CommonTransitions.createFade(400));
mainForm.addCommand(new Command("Left soft key", 2));
mainForm.addCommand(new Command("Right Soft key", 2));
mainForm.show();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
TabbedPane is deprecated from LWUIT
You have below two alternative.
1) use com.sun.lwuit.Tabs.Tabs() and add buttons to it.
i.e.
{
Tabs MenuTabs = new Tabs();
MenuTabs.addTab(button, component);
}
2) Or simply use X asis box layout and add components to it.
Related
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();
});
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.
b1.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent e) {
try {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager
.getConnection("jdbc:mysql://localhost:3306/project?"
+ "user=root&password=virus");
statement = connect.createStatement();
preparedStatement = connect
.prepareStatement("select * from mark where clsnum = " + txt1.getText() + "");
rs = preparedStatement.executeQuery();
if (rs.next()) {
delete();
} else {
msg.setText("Student Not Found...!");
}
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(DeleteMark.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
This is my code to display a message if the query not worked(I mean if no row is returned to ResultSet rs). msg is an object of Text and its declaration and other details are -
Text msg = new Text();
msg.setFont(Font.font("Calibri", FontWeight.THIN, 18));
msg.setFill(Color.RED);
I want to make the Text disappear after sometime, like 3 or 4 seconds. Is it possible to do it in JavaFX (with the help of timer or something else you know) ? If yes, how ?
Use Timelines and/or Transitions.
This answer is for a previous iteration of the question.
Sample solution code
import javafx.animation.*;
import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.util.Duration;
public class BlinkingAndFading extends Application {
#Override
public void start(Stage stage) {
Label label = new Label("Blinking");
label.setStyle("-fx-text-fill: red; -fx-padding: 10px;");
Timeline blinker = createBlinker(label);
blinker.setOnFinished(event -> label.setText("Fading"));
FadeTransition fader = createFader(label);
SequentialTransition blinkThenFade = new SequentialTransition(
label,
blinker,
fader
);
stage.setScene(new Scene(new StackPane(label), 100, 50));
stage.show();
blinkThenFade.play();
}
private Timeline createBlinker(Node node) {
Timeline blink = new Timeline(
new KeyFrame(
Duration.seconds(0),
new KeyValue(
node.opacityProperty(),
1,
Interpolator.DISCRETE
)
),
new KeyFrame(
Duration.seconds(0.5),
new KeyValue(
node.opacityProperty(),
0,
Interpolator.DISCRETE
)
),
new KeyFrame(
Duration.seconds(1),
new KeyValue(
node.opacityProperty(),
1,
Interpolator.DISCRETE
)
)
);
blink.setCycleCount(3);
return blink;
}
private FadeTransition createFader(Node node) {
FadeTransition fade = new FadeTransition(Duration.seconds(2), node);
fade.setFromValue(1);
fade.setToValue(0);
return fade;
}
public static void main(String[] args) {
launch(args);
}
}
Answers to additional questions
lambda expression not expected here lambda expressions are not supported in -source 1.7 (use -source 8 or higher to enable lambda expressions)
You should use Java 8 and not set -source 1.7. If you wish to stick with Java 7 (which I don't advise for JavaFX work), you can replace the Lambda:
blinker.setOnFinished(event -> label.setText("Fading"));
with:
blinker.setOnFinished(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
label.setText("Fading");
}
});
actual and formal argument lists differ in length
Again, you should use Java 8. But if you wish to use Java 7, replace:
stage.setScene(new Scene(new StackPane(label), 100, 50));
with:
StackPane layout = new StackPane();
layout.getChildren().add(label);
stage.setScene(new Scene(layout, 100, 50));
Further recommendations
Good call on not having the text both blink and fade. Blinking text makes for pretty distracting UI, but just fading is fine.
I don't think I'd recommend fading an error message, at least until the user clicks on it or something like that. What if the user didn't see the error message before it faded away?
I am trying to create a very basic RadioGroup with MonoTouch.Dialog. After I select an item in the list of options and go back to the main view, the RadioGroup still shows that the default value is selected. However, when I go to select another item, the previous value I selected is still checked. I have looked at several examples online and none of them seem to be doing anything special to cause the main view to reflect the newly selected value. What am I doing wrong/missing?
Here's a simplified version of my code:
using System;
using MonoTouch.Dialog;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace TestApp
{
public class MainSettings : DialogViewController
{
public MainSettings (UIViewController parent) : base (UITableViewStyle.Grouped, null)
{
Root = new RootElement ("Settings")
{
new Section("Cellular Network")
{
new RootElement("Refresh Data", new RadioGroup(2))
{
new Section()
{
new RadioElement("Every 5 Minutes"),
new RadioElement("Every 15 Minutes"),
new RadioElement("Every 30 Minutes"),
new RadioElement("Hourly"),
new RadioElement("Manually")
}
}
}
};
}
public override void ViewWillAppear (bool animated)
{
NavigationItem.RightBarButtonItem = new UIBarButtonItem ("Close", UIBarButtonItemStyle.Plain, delegate
{
DismissModalViewControllerAnimated (true);
}
);
}
}
}
Thanks,
Randy
It's even more obvious than I originally thought. I wasn't calling base.ViewWillAppear!
I developed RssFeed Application using LWUIT j2me(java) for 2 xml files, now I want to show those 2 xml files on LWUIT Tabs.
That means, when my application runs, default tab will be displayed (on that tab my first Rss xml file Titles should be displayed), and when the user click on tab2 my second Rss xml titles should be displayed.
I am able to display the same titles of one rss files on both the tabs, how to control my flow to achieve my task?
Here my code:
public class XMLMidlet extends MIDlet implements ActionListener {
public XMLMidlet() {
Display.init(this);
news = new Vector();
m_backCommand = new Command("Back");
cmdExit = new Command("EXIT");
cmdDetails = new Command("Details");
}
public void startApp() {
//RssFeed URL's
String urls[] = {"http://topnews-23.rss",
"http://topstory-12.rss"};
for(int i=0;i<urls.length;i++){
ParseThread myThread = new ParseThread(this,urls[i]);
//this will start the second thread
myThread.getXMLFeed(urls[i]);
}
}
//method called by the parsing thread
public void addNews(News newsItem,String url) {
try{
news.addElement(newsItem);
form1 = new Form();
myNewsList = new List(newsVector);
newsList =new List(newsVector);
myNewsList.setRenderer(new NewsListCellRenderer());
newsList.setRenderer(new NewsListCellRenderer());
tabs=new Tabs(Component.TOP);
tabs.addTab("TopNews", myNewsList);
tabs.addTab("Topstory",newsList);
form1.addComponent(tabs);
form1.show();
}
catch(Exception e){
e.printStackTrace();
}
}
You should move below code
myNewsList = new List(newsVector);
newsList =new List(newsVector);
myNewsList.setRenderer(new NewsListCellRenderer());
newsList.setRenderer(new NewsListCellRenderer());
tabs=new Tabs(Component.TOP);
form1 = new Form();
tabs=new Tabs(Component.TOP);
tabs.addTab("TopNews", myNewsList);
tabs.addTab("Topstory",newsList);
from addNews method to constructor XMLMidlet. addNews method should use url parameter to differ for which list the newsItem is directed.
Update
Below is how I think you should implement addNews method:
public void addNews(News newsItem, String url) {
if (url.endsWith("topnews-20.rss")) {
myNewsList.addElement(newsItem);
} else if (url.endsWith("topstory-25.rss")) {
newsList.addElement(newsItem);
}
}
serRenderer does not need to be called from addNews and form1.show() should be moved to startApp.