Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java3D JOptionPan 2
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Thayanithy
JOptionPan 2
6 Answer(s)      5 years and 10 months ago
Posted in : Java3D



Advertisement
View Answers

April 2, 2009 at 4:45 PM


Hi friend,

Code to help in solving the problem :


public class WordDelimiter{

public static void main(String args[]) {
HomePage page = new HomePage();
page.setSize(400, 300);
page.setLocation(200, 100);
page.setVisible(true);
}
}


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class HomePage extends JFrame implements ActionListener {

JLabel label;
JTextArea arr;
private JScrollPane scrollPane;
JButton button;

public HomePage() {
this.setLayout(null);

label = new JLabel("Enter text");
label.setBounds(30, 10, 100, 25);

arr = new JTextArea(100, 10);
this.scrollPane = new JScrollPane(arr);
scrollPane.setBounds(30, 40, 320, 150);

button = new JButton("Submit");
button.setBounds(30, 200, 100, 25);
button.addActionListener(this);

this.add(label);
this.add(scrollPane);
this.add(button);

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
}

public void actionPerformed(ActionEvent e) {

String[] text = arr.getText().split(" ");
List list = new ArrayList();
for (int i = 0; i < text.length; i++) {
list.add(text[i]);
}
MainPage page = new MainPage(list);
page.setSize(400, 300);
page.setLocation(200, 100);
page.setVisible(true);
this.setVisible(false);
}
}




April 2, 2009 at 4:46 PM




import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class MainPage extends JFrame implements ActionListener {

JTextArea arr;
JScrollPane scrollPane;
JButton addString, updateString, deleteString;
List list;

public MainPage(List list) {

this.list = list;

String str = "";
for (int i = 0; i < this.list.toArray().length; i++) {
str = str + this.list.get(i) + " ";
}

this.setLayout(null);
arr = new JTextArea(str, 100, 10);
scrollPane = new JScrollPane(arr);
scrollPane.setBounds(30, 20, 320, 150);

addString = new JButton("Add");
addString.setBounds(30, 200, 80, 25);

updateString = new JButton("Update");
updateString.setBounds(150, 200, 80, 25);

deleteString = new JButton("Delete");
deleteString.setBounds(270, 200, 80, 25);


this.add(scrollPane);
this.add(addString);
this.add(updateString);
this.add(deleteString);

addString.addActionListener(this);
updateString.addActionListener(this);
deleteString.addActionListener(this);

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
}

public void actionPerformed(ActionEvent e) {


if (e.getActionCommand().equals("Add")) {
AddString page = new AddString(this.list);
page.setSize(400, 300);
page.setLocation(200, 100);
page.setVisible(true);
this.setVisible(false);
}

if (e.getActionCommand().equals("Update")) {
UpdateString page = new UpdateString(this.list);
page.setSize(400, 300);
page.setLocation(200, 100);
page.setVisible(true);
this.setVisible(false);
}

if (e.getActionCommand().equals("Delete")) {
deleteString page = new deleteString(this.list);
page.setSize(400, 300);
page.setLocation(200, 100);
page.setVisible(true);
this.setVisible(false);
}
}
}


April 2, 2009 at 4:46 PM




import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

public class AddString extends JFrame implements ActionListener {

JLabel index, text;
JTextField textField, indexField;
JButton submit, cancel;
List list;

public AddString(List list) {
this.list = list;

this.setLayout(null);

index = new JLabel("Index");
index.setBounds(80, 40, 100, 25);

text = new JLabel("Text");
text.setBounds(80, 80, 100, 25);

indexField = new JTextField();
indexField.setBounds(160, 40, 100, 25);

textField = new JTextField();
textField.setBounds(160, 80, 150, 25);

submit = new JButton("Submit");
submit.setBounds(60, 130, 80, 25);

cancel = new JButton("Cancel");
cancel.setBounds(160, 130, 80, 25);

submit.addActionListener(this);
cancel.addActionListener(this);

this.add(index);
this.add(text);
this.add(indexField);
this.add(textField);
this.add(submit);
this.add(cancel);

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
}

public void actionPerformed(ActionEvent e) {
int flag = 0;
if (e.getActionCommand().equals("Submit")) {


try {
list.add(Integer.parseInt(indexField.getText()), textField.getText());
} catch (Exception ex) {
flag = 1;
JOptionPane.showMessageDialog(this,
"Worang index ... ",
"warning",
JOptionPane.WARNING_MESSAGE);
}

if (flag == 0 && textField.getText().trim().equals("")) {

flag = 1;
JOptionPane.showMessageDialog(this,
"Enter some text ... ",
"warning",
JOptionPane.WARNING_MESSAGE);
}
}
if (flag == 0 || e.getActionCommand().equals("Cancel")) {
MainPage page = new MainPage(list);
page.setSize(400, 300);
page.setLocation(200, 100);
page.setVisible(true);
this.setVisible(false);
}
}
}


April 2, 2009 at 4:47 PM



import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

public class UpdateString extends JFrame implements ActionListener {

JLabel index, text;
JTextField textField, indexField;
JButton submit, cancel;
List list;

public UpdateString(List list) {
this.list = list;

this.setLayout(null);

index = new JLabel("Index");
index.setBounds(80, 40, 100, 25);

text = new JLabel("Text");
text.setBounds(80, 80, 100, 25);

indexField = new JTextField();
indexField.setBounds(160, 40, 100, 25);

textField = new JTextField();
textField.setBounds(160, 80, 150, 25);

submit = new JButton("Submit");
submit.setBounds(60, 130, 80, 25);

cancel = new JButton("Cancel");
cancel.setBounds(160, 130, 80, 25);

submit.addActionListener(this);
cancel.addActionListener(this);

this.add(index);
this.add(text);
this.add(indexField);
this.add(textField);
this.add(submit);
this.add(cancel);

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
}

public void actionPerformed(ActionEvent e) {
int flag = 0;
if (e.getActionCommand().equals("Submit")) {


try {
list.set(Integer.parseInt(indexField.getText()), textField.getText());
} catch (Exception ex) {
flag = 1;
JOptionPane.showMessageDialog(this,
"Worang index ... ",
"warning",
JOptionPane.WARNING_MESSAGE);
}

if (flag == 0 && textField.getText().trim().equals("")) {

flag = 1;
JOptionPane.showMessageDialog(this,
"Enter some text ... ",
"warning",
JOptionPane.WARNING_MESSAGE);
}
}
if (flag == 0 || e.getActionCommand().equals("Cancel")) {
MainPage page = new MainPage(list);
page.setSize(400, 300);
page.setLocation(200, 100);
page.setVisible(true);
this.setVisible(false);
}
}
}


April 2, 2009 at 4:47 PM



import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

public class deleteString extends JFrame implements ActionListener {

JRadioButton delete, deleteAll;
JTextField index;
JLabel label;
JButton submit, cancel;
List list;

public deleteString(List list) {
this.list = list;

setLayout(null);

delete = new JRadioButton("Delete Item");
delete.setBounds(30, 40, 100, 25);
delete.setSelected(true);

deleteAll = new JRadioButton("Delete All Item");
deleteAll.setBounds(30, 100, 120, 25);

label = new JLabel("Index");
label.setBounds(70, 70, 100, 25);

index = new JTextField();
index.setBounds(120, 70, 100, 25);

submit = new JButton("Submit");
submit.setBounds(50, 150, 100, 25);

cancel = new JButton("Cancel");
cancel.setBounds(180, 150, 100, 25);

ButtonGroup ButtonGroup = new ButtonGroup();
ButtonGroup.add(delete);
ButtonGroup.add(deleteAll);

add(delete);
add(deleteAll);
add(index);
add(label);
add(submit);
add(cancel);

delete.addActionListener(this);
deleteAll.addActionListener(this);
submit.addActionListener(this);
cancel.addActionListener(this);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public void actionPerformed(ActionEvent e) {

int flag = 0;
if (e.getActionCommand().equals("Delete Item")) {
index.setVisible(true);
label.setVisible(true);
}

if (e.getActionCommand().equals("Delete All Item")) {
index.setVisible(false);
label.setVisible(false);

}

if (e.getActionCommand().equals("Submit") && delete.isSelected()) {
flag = 1;
list.remove(Integer.parseInt(index.getText()));
}

if (e.getActionCommand().equals("Submit") && deleteAll.isSelected()) {
flag = 1;
list.clear();
}

if (e.getActionCommand().equals("Cancel") || flag == 1) {
MainPage page = new MainPage(list);
page.setSize(400, 300);
page.setLocation(200, 100);
page.setVisible(true);
this.setVisible(false);
}
}
}



April 2, 2009 at 4:50 PM


For read more information,examples and tutorials on Swing visit to :

http://www.roseindia.net/java/example/java/swing/

Thanks


Related Tutorials/Questions & Answers:
JOptionPan 2 - Java3D
JOptionPan 2  A sentence can be thought of as one or more words which are delimited by spaces. For example: ?A sentence is constructed with a series... ?A sentence is constructed with a series of words? Index 0 1 2 3
use is of 2
use is of 2  why we use 2 in "Integer.parseInt(str,2);" for binary to decimal conversion..??   ya i got it... because binary contain only two o and 1...so here use 2...same as octal has 8
Advertisements
Magicbox 2
Magicbox 2  how to build this? import java.util.*; class magicbox...; } } } } v15=a[0][0]+a[0][1]+a[0][2]==15 && a[1][0]+a[1][1]+a[1][2]==15 && a[2][0]+a[2][1]+a[2][2]==15 &&
Struts 2
Struts 2  we can extend DispatchAction class to implement a common session validation in struts 1.x. how to do the same in the struts2
Struts 2
Struts 2   I am just new to struts 2 and need to do the task. I have a requirement like this : when i click on link like Customer , this will display all the customers , address from a database table using jdbc and the screen
Struts 2
Struts 2  I am getting the following error.pls help me out. The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has
new 2
new 2  <%@page import="java.util.ArrayList"%> <%@page...; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2 sevelet @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2 import java.io.IOException; import java.io.PrintWriter; import
Echo 2
Echo 2       Echo 2 allows you to code Ajax apps in pure Java (Demo)which automatically generates HTML and Javascript. Read full Description
FireFox 2
FireFox 2       The award... to do on the Web, and Firefox 2 is full of helpful features to make your... Add-ons that enhance Firefox. It?s easy to personalize Firefox 2
Thunderbird 2
Thunderbird 2       Mozilla?s Thunderbird 2 email application is more powerful than ever. It?s now... Information Organized Thunderbird 2 features many new enhancements to help
struts 2 testing
struts 2 testing  can i get an example for struts 2 action class unit test
regarding struts 2
regarding struts 2   is it not possible to get values from applicationresources.properties into our application in struts 2
Struts 2 - Validation - Struts
Struts 2 - Validation annotations  digging for a simple struts 2 validation annotations example
2's Complement
2's Complement  hi Can anyone plsss tell me the 2's complement java program... Thanks in advance
Where to learn Struts 2?
Where to learn Struts 2?  Hi, I am beginner in Struts and trying to find good tutorial to learn Struts 2 framework. My project is in Struts 2 and soon I have to work on the project. Let's know where to learn the Struts 2
Struts 2 Video Tutorial
Struts 2 Video Tutorial  I think its easy to learn from Struts 2 Video Tutorial. What is the url of Struts 2 Video Tutorial on roseindia.net website... your are right. You can learn Struts 2 very easily with the Struts 2 Video
Struts 2 online tutorial
Struts 2 online tutorial  Where to learn struts 2 online tutorial? Is there any good tutorials on roseindia.net for learning struts 2 online tutorial?   Yes, We have many tutorials for learning Struts 2 online through
What is Struts 2 framework
What is Struts 2 framework  Hi, I am new to the Java web programming. I have completed JSP, Servlet and HTML. Now I want to learn Struts 2. Tell me what is Struts 2? Thanks
Struts 2 + hibernate
Struts 2 + hibernate  How to integrate Struts 2 and Hibernate? Its urgent please help!!   See the example give below.. for integrating struts 2 and hibernate. Struts2.2.1 and hibernate integration application Integrate
Struts 2 + Hibernate
Struts 2 + Hibernate  From where can i get good tutorial from integrating struts 2 with hibernate , which explains step by step procedure in integration and to build web applications
struts 2 project samples
struts 2 project samples  please forward struts 2 sample projects like hotel management system. i've done with general login application and all. Ur answers are appreciated. Thanks in advance Raneesh
Strurt 2 TLD - WebSevices
Strurt 2 TLD  pls any one can send me either link to download or actual TLD files of struts 2 i nead the TLD files but i could not found
struts 2 tabbedpanel - Struts
struts 2 tabbedpanel  Hi Friend do I change the background color of a tab? bye bye
Query Question 2
Query Question 2  Want to displays the name and ID of all departments with the names of the employees in that department. SELECT * FROM employee is my result
Compare 2 files
Compare 2 files  I would like to compare 2 files in Java. please send me the code snipt for this scenario: File1... file 1 and 2. The file name will normally be the last 16 characters of a line
Maven 2 - Maven
Maven 2   Hi, I m new to Maven 2 and in process to implement Maven2. I have browse in the net and got my Maven 2 installed but now I m facing few concerns on creating a small project. Please help me in this regard Thanks
Printing 2 arrays
Printing 2 arrays  Hi, I have 2 arrays: String [] head = {"Name... want this 2 arrays to be printed out in the following manner: head[0] tab personal[0] head[1] tab personal[1] head[2] tab personal [2] I tried different
Struts 2 - Beganner
Struts 2 - Beganner  Hi ! I am new to Struts2 and I need clarification over Difference between Action Proxy and Action Mapper in struts2 and When both perform their activity?????? Many Thanks Venkateshlu
zend framework 2
zend framework 2  i am new in zf2 and i want to develop a website in zf2 so can anyone help me to figure out the(login and signup page) with database
struts 2 mysql
struts 2 mysql  In the example : http://www.roseindia.net/struts/struts2/struts-2-mysql.shtml how is the username and password(in insertdata.jsp) which is entered by the user is transferred to the { ("INSERT employee VALUES
Divide 2 numbers
Divide 2 numbers  Write a java program to divide 2 numbers. Avoid division by zeor by catching the exception.   class Divide { public static void main(String[] args) { try{ int num1=8
Advertisements
 

 

 

DMCA.com