Showing user input in a JFrame
i need to be able to take user-given values and display them in a JFrame. i'm testing the input of a sudoku puzzle. i have a sudokuComponent and a sudokuViewer.
i'm confused as to where to place my code that will do the process of taking user input (via Scanner class) and testing it for certain conditions.
i dont think figuring out the testing conditions should be hard, i'm just having trouble with getting the input read in correctly and a way of getting it displayed on the JFrame which displays the sudoku puzzle with the values so far.
i was given a tip that said i needed to use the method repaint() of JFrame to see the updates.
SUDOKUCOMPONENT
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Line2D;
import javax.swing.JPanel;
import javax.swing.JComponent;
import java.util.Scanner;
public class SudokuComponent extends JComponent
public void paintComponent(Graphics g)
//recover graphics2s
Graphics2D g2 = (Graphics2D) g;
//Construct the Sudoku square
Rectangle box = new Rectangle(20, 20, 270, 270);
g2.draw(box);
g2.draw(new Line2D.Double(20, 110, 290, 110)); //horizontal
g2.draw(new Line2D.Double(20, 200, 290, 200));
g2.draw(new Line2D.Double(110, 20, 110, 290)); //vertical
g2.draw(new Line2D.Double(200, 20, 200, 290));
}SUDOKUVIEWER
import javax.swing.JFrame;
import java.util.Scanner;
public class SudokuViewer
public static void main(String[] args)
JFrame frame = new JFrame();
final int FRAME_WIDTH = 350;
final int FRAME_HEIGHT = 350;
frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
frame.setTitle("Sudoku Viewer");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
SudokuComponent component = new SudokuComponent();
frame.add(component);
frame.setVisible(true);
}
I have improved your application to show how it can be programmed.
For more information you can see about
KeyListener:
http://java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html
MouseListener:
http://java.sun.com/docs/books/tutorial/uiswing/events/mouselistener.html
and of course use repaint() when you want to update your component
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.Line2D;
import java.util.LinkedList;
import java.util.List;
import javax.swing.JComponent;
public class SudokuComponent extends JComponent {
SudokuElement currentElement = new SudokuElement();
List<SudokuElement> elementList = new LinkedList<SudokuElement>();
public SudokuComponent(){
addMouseListener(new MyMouseListener());
setFocusable(true);
addKeyListener(new MyKeyListener());
public void paintComponent(Graphics g) {
//public void paint(Graphics g) {
//recover graphics2s
Graphics2D g2 = (Graphics2D) g;
//Construct the Sudoku square
Rectangle box = new Rectangle(20, 20, 270, 270);
g2.draw(box);
g2.draw(new Line2D.Double(20, 110, 290, 110)); //horizontal
g2.draw(new Line2D.Double(20, 200, 290, 200));
g2.draw(new Line2D.Double(110, 20, 110, 290)); //vertical
g2.draw(new Line2D.Double(200, 20, 200, 290));
// show place where user can type a digit
g2.draw(new Line2D.Double(currentElement.x - 10, currentElement.y, currentElement.x + 10, currentElement.y));
// show all typed digits
for(SudokuElement elem : elementList ){
g2.drawString(elem.digit + "", elem.x, elem.y);
class SudokuElement {
int digit;
int x;
int y;
SudokuElement getCopy(){
SudokuElement elem = new SudokuElement();
elem.x = x;
elem.y = y;
elem.digit= digit;
return elem;
class MyMouseListener extends MouseAdapter {
public void mouseClicked(MouseEvent e) {
System.out.println("mouse clicked: x = " + e.getX() + " y = " + e.getY());
currentElement.x = e.getX(); // It is better to use local coordinats 0 .. 9
currentElement.y = e.getY();
repaint();
class MyKeyListener extends KeyAdapter {
public void keyTyped(KeyEvent e) {
char ch = e.getKeyChar();
System.out.println("char typed= " + ch);
if( Character.isDigit(ch) ){ // Filter only digits
currentElement.digit = Character.digit(ch, 10);
elementList.add(currentElement.getCopy());
repaint();
}
Similar Messages
-
How i can show the user input in alv list on the top
hi all,
please tell me how i can show the user input in alv list on the top.
and also tell me how i can hide the toolbar in alv.
regards
vikas sainiHi,
Use the Below Code.
form top_of_page.
data : it_header type slis_t_listheader,
is_header type slis_listheader.
is_header-typ = c_h.
is_header-key = space.
is_header-info = 'Pending Order Information Report'(018).
append is_header to it_header.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = it_header.
endform. "top_of_page
and finally pass it to .
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = sy-repid
i_callback_top_of_page = 'TOP_OF_PAGE'
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = sy-repid
i_callback_top_of_page = 'TOP_OF_PAGE'
Regards.
Arbind -
Quiz Results - Showing the users input
Could you tell me if there is away to display or print the users input to the questions slides on to one page.
My Learners take an assessment on their induction course. Using Trainersoft I can display one page showing their answers to the questions. I then print this off and we go through it to see where their strengths and weaknesses are. I cant seem to do this with Captivate 4.
I know about review quiz option (one page at a time) but when you have a classroom of up to 16 people it isn't practical.
Thank you in advanceHi,
Although this may not be an easy one to accomplish in CP4, but still you can use Variables and Scripting to store and display the user responses on a slide.
Whenever a student answers some question, you can store some strings w.r.t the response, in a user variable (created by you) and then display it using a text caption on a slide. In this way, you can always show the response of the student with a custom message also.
This will become more easy with the new features of CP5.
http://www.adobe.com/products/captivate/features/?view=topnew
Regards
Chinmay -
Showing applets depending upon user input in one web page
hi, I have three applets. I want to create a webpage, put three buttons (or other interactions) on it. If button one is clicked, applet one is shown. If button two is clicked, applet two is shown. I want this to happen in one web page only and one applet at a time depending on user input. Is there a way to do it? Do I need to use javascript? I am new to javascript ,but if you can point me to relevant javascript topics, i am willing to learn it. Thanks.
There are a couple of ways I can think of off the bat...
1) Create an IFrame that the Applet will be displayed in. The button you press submits a form whose target is the IFrame and whose action is a page with the correct Applet.
2) Actually load all 3 Applets on the page and hide them all in a invisible divs. The button calls a javascript function that unhides a specific div (and hides all the others to be sure only one is displayed at a time).
3) Uber-javascript AJAX like control that when the button is pushed makes a request to a page that returns the applet tag which the javascript control then inserts into the page at the proper location.
I would toss up between 1 & 2.
For code, search Google for important key words (like "form target iframe", or "javascript make divs invisible"). -
How to force to wait and get input from a jframe-jpanel?
I would like to use a jframe-jpanel to get user input instead of using JOptionPane.showInputDialog since there will be more than 1 input.
But I could not do it. The code reads the panel lines and passes to other lines below without waiting for the okay button to be pressed.
This is the part of code of my main frame;
jLabel10.setText(dene.toString());
if (dene == 0) {
// todo add button input panel
//String todo_write = JOptionPane.showInputDialog("Please enter a todo item");
JFrame frameTodoAddInput = new JFrame( "Please input..." );
TodoAddAsk1JPanel todoaddpanel = new TodoAddAsk1JPanel();
frameTodoAddInput.add(todoaddpanel);
frameTodoAddInput.setSize( 600, 200 ); // set frame size
frameTodoAddInput.setLocation(300, 300);
//String todo_write = todoaddpanel.getNewTodoItem();
String todo_write = todoaddpanel.getNewTodoItem();
jLabel10.setText("Satir 1822 de".concat(todo_write));
// end of todo add button input panel
todoTextPane1.setText(todo_write);
This is the code of input panel;
* TodoAddAsk1JPanel.java
* Created on May 6, 2007, 12:03 AM
package javaa;
public class TodoAddAsk1JPanel extends javax.swing.JPanel {
/** Creates new form TodoAddAsk1JPanel */
public TodoAddAsk1JPanel() {
initComponents();
private String NewTodoItem = "";
public String getNewTodoItem() {
NewTodoItem = ANewTodoItemTextField.getText();
return this.NewTodoItem;
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
ANewTodoItemTextField = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
PriorityComboBox = new javax.swing.JComboBox();
jLabel3 = new javax.swing.JLabel();
DayValueComboBox = new javax.swing.JComboBox();
MonthValueComboBox = new javax.swing.JComboBox();
YearValueComboBox = new javax.swing.JComboBox();
OkayButton = new javax.swing.JButton();
CancelButton = new javax.swing.JButton();
TimeValueComboBox = new javax.swing.JComboBox();
jLabel1.setText("Please enter a todo item:");
jLabel2.setText("Please select its priority level:");
PriorityComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "A", "B", "C" }));
jLabel3.setText("Please select its due date:");
DayValueComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
MonthValueComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }));
YearValueComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020", "2021", "2022", "2023", "2024", "2025", "2026", "2027", "2028", "2029", "2030", "2031", "2032", "2033", "2034", "2035", "2036", "2037", "2038", "2039", "2040", "2041", "2042", "2043", "2044", "2045", "2046", "2047", "2048", "2049", "2050", "2051", "2052", "2053", "2054", "2055", "2056", "2057", "2058", "2059", "2060", "2061", "2062", "2063", "2064", "2065", "2066", "2067", "2068", "2069", "2070" }));
OkayButton.setText("OK");
OkayButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
OkayButtonActionPerformed(evt);
CancelButton.setText("Cancel");
TimeValueComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "08:30", "09:00", "09:30", "10:00", "10:30", "11:00", "11:30", "12:00", "12:30", "13:00", "13:30", "14:00", "14:30", "15:00", "15:30", "16:00", "16:30", "17:00", "17:30", "18:00", "18:30", "19:00", "19:30", "20:00", "20:30", "21:00", "21:30", "22:00", "22:30", "23:00", "23:30", "00:00", "00:30", "01:00", "01:30", "02:00", "02:30", "03:00", "03:30", "04:00", "04:30", "05:00", "05:30", "06:00", "06:30", "07:00", "07:30", "08:00" }));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE)
.addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(PriorityComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ANewTodoItemTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 279, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(OkayButton, javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 133, Short.MAX_VALUE)
.addComponent(CancelButton))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(DayValueComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(MonthValueComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(YearValueComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(13, 13, 13)
.addComponent(TimeValueComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(42, 42, 42)))
.addContainerGap())
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ANewTodoItemTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(PriorityComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(DayValueComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(MonthValueComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(YearValueComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(TimeValueComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(OkayButton)
.addComponent(CancelButton))
.addContainerGap())
}// </editor-fold>
private void OkayButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
NewTodoItem = ANewTodoItemTextField.getText();
// Variables declaration - do not modify
private javax.swing.JTextField ANewTodoItemTextField;
private javax.swing.JButton CancelButton;
private javax.swing.JComboBox DayValueComboBox;
private javax.swing.JComboBox MonthValueComboBox;
private javax.swing.JButton OkayButton;
private javax.swing.JComboBox PriorityComboBox;
private javax.swing.JComboBox TimeValueComboBox;
private javax.swing.JComboBox YearValueComboBox;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
// End of variables declaration
I want to get the resulted input of "NewTodoItem"
Thanks in advance for your kind help.
GuvenThank you very much for your help. But I would like
to get 3 inputs from 1 window at the same time and I
could not find any example code for JDialog for more
than 1 input. If any body can show how to write this
code, it would be appreciated.
ThanksYou can write your own. A JDialog is a container just look a JFrame is. -
How to make Flash to wait for user input
Hi,
I found this PHP script, then I made some changes to make it
FEED the Flash user interface with online user input.
The main concept of this script is WAITING for user input, so
it shows the messages and then go to next line and so on.
The user input go to directly to TEXT file which writes in
lines, each line has a unique id = (mag_id).
There "get_msge.php" which works as the middleware between
FLASH and messages text file.
The problem, its doesn’t show any data while there are
data in the text file.
Help here please, best regards.
This is the link of
problem illustartion
AS is:
// create an object to store the variables
varReceiver = new LoadVars();
// load the variables from the text file
varReceiver.load("get_msg.php?file_id=1&msg_id=1",
"POST");
// trigger something - when the variables finish loading
varReceiver.onLoad = function(){
//the variables have finished loading
if (this.msg_id == 1) {
_root.xmsg1_swf.text = this.msg;
_root.xmsg1_ch.text = this.msg;
gotoAndPlay("line2");
} else {WAIT }
PHP is:
<?php
//get these values from the FLASH
$file_id_swf = $_POST ['file_id'];
$file_name = "messages/messages".$file_id_swf.".txt";
$msg_id_swf = $_POST ['msg_id'];
// [0] ."||".[1] ."||".[2] ."||". [3] ."||".[4]."||". [5].
//$msg_id."||".date."||".time."||".$from."||".$to."||".$msg.
$fp = fopen ($file_name, 'rb');
while (!feof ($fp))
$msg_txt = fgets ($fp, 1024);
$line = explode ("||", $msg_txt);
$msg_id = $line[0];
$from = $line[3];
$to = $line[4];
$msg = utf8_encode ($line[5]);
if ($msg_id == $msg_id_swf)
echo
"msg_id=".$msg_id."&from=".$from."&to=".$to."&msg=".$msg;
}//while
fclose ($fp);
?>Well, given the things that you've written, I don't think it
could. There technically isn't any code in flash that lets it
"wait." In order to "wait," you must run the script over again
until some condition is met.
However, your code does look accurate. Why do you need to
wait? The onLoad function will be invoked WHEN something is loaded.
So, I don't see the reason for the "waiting."
In addition to that, I would like to say that using text
files isn't that great with flash. I have done this before and
noticed several problems with using text files. The biggest problem
is that the text files are cached after being loaded. Every time
you re-load it again, you will get what you got the first time
until you reset your cache (ie. close your browser). I suggest
using MySQL. (Just my thought.) -
Help needed, Createing Dynamic User input
Hello,
I am attempting to create some dynamic user input by "predicting" what the user requires in a text box.
For example if the user enters "Smi" I have a select list pop up which gives the user all options that begin with "Smi".
I am able to achieve the popups but the interface is quite jerky and not terribly responsive I am trying to solve this by using a thread which starts and stops when new input is received but it is still not quite right.
The program uses a Sorted TreeSet to hold the data (I thought this would give me a quick search time) and a simple interface at this stage.
Any help would be fantastic
Thanks in advance :P
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.text.*;
import java.util.*;
/** This program represents part of a larger user interface for allowing the
user to select data from a file or database.
<p>
When the program starts up, it will read in data from a given file, and hold
it in some type of container allowing rapid access.
<p>
The user may then type in the first few letters of the surname of a person,
and this program should immediately present in a popup dialog the names which
match. The user will be able to click on one of the names in the popup and
that will cause all data about that person to be displayed in the JTextArea
at the bottom of the window.
<p>
This program requires the FormLayout.class, FormLayout$Placement.class, and
FormLayout$Constraint.class files in the same directory
(folder) or in its classpath. These is provided separately.
class PartMatch extends JFrame implements Runnable
/** Close down the program. */
JButton quitbtn;
/** Field for the surname. */
JTextField namefld;
/** Full details of the person(s). */
JTextArea results;
/** Popup dialog to display the names and addresses which
match the leading characters given in namefld. */
Chooser matches;
/** Default background color for a window. */
final static Color defBackground = new Color(0xD0C0C0);
/** Default foreground color for a window. */
final static Color defForeground = new Color(0x000000);
/** Default background color for a field */
final static Color fldBackground = new Color(0xFFFFFF);
/** Default background color for a button */
final static Color btnBackground = new Color(0xF0E0E0);
final static Color dkBackground = new Color(0xB0A0A0);
/** Larger font */
final static Font bold = new Font("Helvetica", Font.BOLD, 30);
TreeSet members;
String input;
String[] found;
public static void main(String arg[])
UIManager.put("TextField.background",fldBackground);
UIManager.put("TextField.foreground",defForeground);
UIManager.put("TextField.selectionBackground",btnBackground);
UIManager.put("TextArea.background",fldBackground);
UIManager.put("TextArea.foreground",defForeground);
UIManager.put("TextArea.selectionBackground",btnBackground);
UIManager.put("Panel.background",defBackground);
UIManager.put("Label.background",defBackground);
UIManager.put("Label.foreground",defForeground);
UIManager.put("Button.background",btnBackground);
UIManager.put("Button.foreground",defForeground);
UIManager.put("CheckBox.background",defBackground);
UIManager.put("ScrollBar.background",defBackground);
UIManager.put("ScrollBar.thumb",btnBackground);
UIManager.put("ComboBox.background",btnBackground);
UIManager.put("ComboBox.selectionBackground",dkBackground);
PartMatch trial = new PartMatch(arg);
public PartMatch( String [] arg )
super("Part Match");
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container cpane = getContentPane();
FormLayout form = new FormLayout(cpane);
JLabel lab1 = new JLabel("Fetch details") ;
lab1.setFont( bold );
form.setTopAnchor( lab1, 4 );
form.setLeftAnchor( lab1, 4 );
JLabel lab2 = new JLabel("Surname: ") ;
form.setTopRelative( lab2, lab1, 4 );
form.setLeftAlign( lab2, lab1 );
namefld = new JTextField( 30 );
form.setBottomAlign( namefld, lab2 );
form.setLeftRelative( namefld, lab2, 4 );
namefld.addCaretListener( new CaretListener()
public void caretUpdate(CaretEvent e)
showMatches();
quitbtn = new JButton( "Quit" );
quitbtn.addActionListener( new ActionListener()
public void actionPerformed(ActionEvent e)
quitProcessing();
form.setBottomAlign( quitbtn, namefld );
form.setLeftRelative( quitbtn, namefld, 15 );
results = new JTextArea( 10,50 );
results.setEditable(false);
JScrollPane jsp = new JScrollPane( results,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
form.setTopRelative( jsp, lab2, 6 );
form.setLeftAlign( jsp, lab2 );
form.setBottomAnchor( jsp, 5 );
form.setRightAnchor( jsp, 5 );
form.setRightAnchor( quitbtn, 5 );
matches = new Chooser( this );
//matches.setUndecorated(true);
pack();
setVisible(true);
namefld.requestFocus();
if (arg.length > 0) init(arg[0]);
else init("triathlon.txt"); //<<<<<<<<<<<<<<<< Place the default filename here
/** Called once only, at the end of the constructor, to read the data
* from the membership file.
public void init( String fname )
members = new TreeSet();
try {
FileReader fr = new FileReader(new File (fname));
Scanner scan = new Scanner(fr);
trimember cmem;
String cLine, eTag, memberNo, first, last, gender, yob, tel ,addr,
club;
while(scan.hasNextLine())
cLine = scan.nextLine();
Scanner scan2 = new Scanner(cLine);
scan2.useDelimiter(";");
eTag = scan2.next().trim();
memberNo = scan2.next().trim();
first = scan2.next().trim();
last = scan2.next().trim();
gender = scan2.next().trim();
yob = scan2.next().trim();
tel = scan2.next().trim();
addr = scan2.next().trim();
club = scan2.next().trim();
cmem = new trimember(eTag, memberNo, first, last, gender, yob,
tel, addr, club);
members.add(cmem);
catch (FileNotFoundException ex)
results.append("Sorry can't find the input file\n");
results.append("Please check file name and location and try again");
ex.printStackTrace();
/** Called every time there is a change in the contents of the text field
* namefld. It will first clear the text area. It then needs to search
* through the container of data to find all records where the surname
* starts with the characters that have been typed. The names and
* addresses need to be set up as strings and placed in
* an array of Strings. This can be placed in the "matches" window and
* displayed for the user, inviting one to be selected.
* <p>
* The performance of this is very important. If necessary, it may be
* necessary to run as a separate thread so that the user interface is
* not delayed. It is essential that the user be able to type letters at a
* reasonable speed and not have the keystroke processing held up by
* previous text.
public void showMatches( )
run();
// First clear the text area
//results.setText("");
// Determine the leading characters of the surname that is wanted
input = namefld.getText();
// Locate the data for this name, and display each matching item
// in the JTextArea ...
// Example of how to set the data in the popup dialog
matches.list.setListData(found);
matches.pack(); // resize the popup
// set the location of the popup if it is not currently visible
if ( ! matches.isVisible())
Dimension sz = matches.getSize();
Point mouse = getMousePosition();
Point framepos = getLocation();
int x=0, y=0;
if (mouse == null)
Point pt = results.getLocation();
x = pt.x + 20 + framepos.x;
y = pt.y + 20 + framepos.y;
else
x = mouse.x - 2 + framepos.x;
y = mouse.y - 2 + framepos.y;
matches.setLocation(x,y);
matches.setVisible(true);
namefld.requestFocus();
/** Perform any final processing before closing down.
public void quitProcessing( )
// Any closing work. Then
System.exit(0);
public void run()
ArrayList<String> foundit = new ArrayList<String>();
System.out.println(input);
if(input != null)
Iterator it = members.iterator();
while(it.hasNext())
trimember test = (trimember) it.next();
if (test.last.startsWith(input))
foundit.add(test.last +", "+ test.first);
found = new String[foundit.size()];
for(int i=0; i<foundit.size();i++)
found[i] = foundit.get(i);
/** A window for displaying names and addresses from the data set which
match the leading characters in namefld.
<p>
This will automatically pop down if the user moves the mouse out of the
window.
<p>
It needs code added to it to respond to the user clicking on an item in
the displayed list. */
class Chooser extends JWindow
/** To display a set of names and addresses that match the leading
characters of the namefld text field. */
public JList list = new JList();
Chooser( JFrame parent )
super( parent );
Container cpane = getContentPane();
cpane.addMouseListener( new MouseAdapter()
public void mouseExited(MouseEvent e)
Chooser.this.setVisible(false);
cpane.add("Center",list);
list.addListSelectionListener( new ListSelectionListener()
public void valueChanged(ListSelectionEvent e)
Chooser.this.setVisible(false);
System.out.println("ValueChanged");
// First clear the text area
results.setText("");
String in = (String) list.getSelectedValue();
System.out.println("Selected Value was : "+in);
String[] inlf = in.split(", ");
System.out.println("inlf[0]:"+inlf[0]+" inlf[1]:"+inlf[1]);
results.append("Surname \tFirst \teTag \tMemberNo \tSex \tYOB " +
"\tTel \tAddress \t\t\tClub\n");
Iterator it = members.iterator();
while(it.hasNext())
trimember test = (trimember) it.next();
if (test.last.equals(inlf[0])&&test.first.equals(inlf[1]))
results.append(test.toString()+"\n");
namefld.requestFocus();
public class trimember implements Comparable
String eTag;
public String memberNo;
public String first;
public String last;
String gender;
String yob;
String tel;
String addr;
String club;
public trimember(String eT, String me, String fi, String la,
String ge, String yo, String te, String ad, String cl)
eTag = eT;
memberNo = me;
first = fi;
last = la;
gender = ge;
yob = yo;
tel = te;
addr = ad;
club = cl;
//To String method to output string of details
public String toString()
return last + "\t" + first + "\t" + eTag + "\t" +
memberNo + "\t" + gender + "\t" + yob + "\t"+ tel + "\t" +
addr + "\t" + club;
//Compare and sort on Last name
public int compareTo(Object o)
trimember com = (trimember) o;
int lastCmp = last.compareTo(com.last);
int firstCmp = first.compareTo(com.first);
int memCmp = memberNo.compareTo(com.memberNo);
if (lastCmp == 0 && firstCmp !=0)return firstCmp;
else if (lastCmp==0&&firstCmp==0)return memCmp;
else return lastCmp;
}Please don't cross-post. It is considered very rude to do that here:
http://forum.java.sun.com/thread.jspa?messageID=9953193 -
Help needed, Providing Dynamic User input
Hello,
I am attempting to create some dynamic user input by "predicting" what the user requires in a text box.
For example if the user enters "Smi" I have a select list pop up which gives the user all options that begin with "Smi".
I am able to achieve the popups but the interface is quite jerky and not terribly responsive I am trying to solve this by using a thread which starts and stops when new input is received but it is still not quite right.
The program uses a Sorted TreeSet to hold the data (I thought this would give me a quick search time) and a simple interface at this stage.
Any help would be fantastic
Thanks in advance :P
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.text.*;
import java.util.*;
/** This program represents part of a larger user interface for allowing the
user to select data from a file or database.
<p>
When the program starts up, it will read in data from a given file, and hold
it in some type of container allowing rapid access.
<p>
The user may then type in the first few letters of the surname of a person,
and this program should immediately present in a popup dialog the names which
match. The user will be able to click on one of the names in the popup and
that will cause all data about that person to be displayed in the JTextArea
at the bottom of the window.
<p>
This program requires the FormLayout.class, FormLayout$Placement.class, and
FormLayout$Constraint.class files in the same directory
(folder) or in its classpath. These is provided separately.
class PartMatch extends JFrame implements Runnable
/** Close down the program. */
JButton quitbtn;
/** Field for the surname. */
JTextField namefld;
/** Full details of the person(s). */
JTextArea results;
/** Popup dialog to display the names and addresses which
match the leading characters given in namefld. */
Chooser matches;
/** Default background color for a window. */
final static Color defBackground = new Color(0xD0C0C0);
/** Default foreground color for a window. */
final static Color defForeground = new Color(0x000000);
/** Default background color for a field */
final static Color fldBackground = new Color(0xFFFFFF);
/** Default background color for a button */
final static Color btnBackground = new Color(0xF0E0E0);
final static Color dkBackground = new Color(0xB0A0A0);
/** Larger font */
final static Font bold = new Font("Helvetica", Font.BOLD, 30);
TreeSet members;
String input;
String[] found;
public static void main(String arg[])
UIManager.put("TextField.background",fldBackground);
UIManager.put("TextField.foreground",defForeground);
UIManager.put("TextField.selectionBackground",btnBackground);
UIManager.put("TextArea.background",fldBackground);
UIManager.put("TextArea.foreground",defForeground);
UIManager.put("TextArea.selectionBackground",btnBackground);
UIManager.put("Panel.background",defBackground);
UIManager.put("Label.background",defBackground);
UIManager.put("Label.foreground",defForeground);
UIManager.put("Button.background",btnBackground);
UIManager.put("Button.foreground",defForeground);
UIManager.put("CheckBox.background",defBackground);
UIManager.put("ScrollBar.background",defBackground);
UIManager.put("ScrollBar.thumb",btnBackground);
UIManager.put("ComboBox.background",btnBackground);
UIManager.put("ComboBox.selectionBackground",dkBackground);
PartMatch trial = new PartMatch(arg);
public PartMatch( String [] arg )
super("Part Match");
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container cpane = getContentPane();
FormLayout form = new FormLayout(cpane);
JLabel lab1 = new JLabel("Fetch details") ;
lab1.setFont( bold );
form.setTopAnchor( lab1, 4 );
form.setLeftAnchor( lab1, 4 );
JLabel lab2 = new JLabel("Surname: ") ;
form.setTopRelative( lab2, lab1, 4 );
form.setLeftAlign( lab2, lab1 );
namefld = new JTextField( 30 );
form.setBottomAlign( namefld, lab2 );
form.setLeftRelative( namefld, lab2, 4 );
namefld.addCaretListener( new CaretListener()
public void caretUpdate(CaretEvent e)
showMatches();
quitbtn = new JButton( "Quit" );
quitbtn.addActionListener( new ActionListener()
public void actionPerformed(ActionEvent e)
quitProcessing();
form.setBottomAlign( quitbtn, namefld );
form.setLeftRelative( quitbtn, namefld, 15 );
results = new JTextArea( 10,50 );
results.setEditable(false);
JScrollPane jsp = new JScrollPane( results,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
form.setTopRelative( jsp, lab2, 6 );
form.setLeftAlign( jsp, lab2 );
form.setBottomAnchor( jsp, 5 );
form.setRightAnchor( jsp, 5 );
form.setRightAnchor( quitbtn, 5 );
matches = new Chooser( this );
//matches.setUndecorated(true);
pack();
setVisible(true);
namefld.requestFocus();
if (arg.length > 0) init(arg[0]);
else init("triathlon.txt"); //<<<<<<<<<<<<<<<< Place the default filename here
/** Called once only, at the end of the constructor, to read the data
* from the membership file.
public void init( String fname )
members = new TreeSet();
try {
FileReader fr = new FileReader(new File (fname));
Scanner scan = new Scanner(fr);
trimember cmem;
String cLine, eTag, memberNo, first, last, gender, yob, tel ,addr,
club;
while(scan.hasNextLine())
cLine = scan.nextLine();
Scanner scan2 = new Scanner(cLine);
scan2.useDelimiter(";");
eTag = scan2.next().trim();
memberNo = scan2.next().trim();
first = scan2.next().trim();
last = scan2.next().trim();
gender = scan2.next().trim();
yob = scan2.next().trim();
tel = scan2.next().trim();
addr = scan2.next().trim();
club = scan2.next().trim();
cmem = new trimember(eTag, memberNo, first, last, gender, yob,
tel, addr, club);
members.add(cmem);
catch (FileNotFoundException ex)
results.append("Sorry can't find the input file\n");
results.append("Please check file name and location and try again");
ex.printStackTrace();
/** Called every time there is a change in the contents of the text field
* namefld. It will first clear the text area. It then needs to search
* through the container of data to find all records where the surname
* starts with the characters that have been typed. The names and
* addresses need to be set up as strings and placed in
* an array of Strings. This can be placed in the "matches" window and
* displayed for the user, inviting one to be selected.
* <p>
* The performance of this is very important. If necessary, it may be
* necessary to run as a separate thread so that the user interface is
* not delayed. It is essential that the user be able to type letters at a
* reasonable speed and not have the keystroke processing held up by
* previous text.
public void showMatches( )
run();
// First clear the text area
//results.setText("");
// Determine the leading characters of the surname that is wanted
input = namefld.getText();
// Locate the data for this name, and display each matching item
// in the JTextArea ...
// Example of how to set the data in the popup dialog
matches.list.setListData(found);
matches.pack(); // resize the popup
// set the location of the popup if it is not currently visible
if ( ! matches.isVisible())
Dimension sz = matches.getSize();
Point mouse = getMousePosition();
Point framepos = getLocation();
int x=0, y=0;
if (mouse == null)
Point pt = results.getLocation();
x = pt.x + 20 + framepos.x;
y = pt.y + 20 + framepos.y;
else
x = mouse.x - 2 + framepos.x;
y = mouse.y - 2 + framepos.y;
matches.setLocation(x,y);
matches.setVisible(true);
namefld.requestFocus();
/** Perform any final processing before closing down.
public void quitProcessing( )
// Any closing work. Then
System.exit(0);
public void run()
ArrayList<String> foundit = new ArrayList<String>();
System.out.println(input);
if(input != null)
Iterator it = members.iterator();
while(it.hasNext())
trimember test = (trimember) it.next();
if (test.last.startsWith(input))
foundit.add(test.last +", "+ test.first);
found = new String[foundit.size()];
for(int i=0; i<foundit.size();i++)
found[i] = foundit.get(i);
/** A window for displaying names and addresses from the data set which
match the leading characters in namefld.
<p>
This will automatically pop down if the user moves the mouse out of the
window.
<p>
It needs code added to it to respond to the user clicking on an item in
the displayed list. */
class Chooser extends JWindow
/** To display a set of names and addresses that match the leading
characters of the namefld text field. */
public JList list = new JList();
Chooser( JFrame parent )
super( parent );
Container cpane = getContentPane();
cpane.addMouseListener( new MouseAdapter()
public void mouseExited(MouseEvent e)
Chooser.this.setVisible(false);
cpane.add("Center",list);
list.addListSelectionListener( new ListSelectionListener()
public void valueChanged(ListSelectionEvent e)
Chooser.this.setVisible(false);
System.out.println("ValueChanged");
// First clear the text area
results.setText("");
String in = (String) list.getSelectedValue();
System.out.println("Selected Value was : "+in);
String[] inlf = in.split(", ");
System.out.println("inlf[0]:"+inlf[0]+" inlf[1]:"+inlf[1]);
results.append("Surname \tFirst \teTag \tMemberNo \tSex \tYOB " +
"\tTel \tAddress \t\t\tClub\n");
Iterator it = members.iterator();
while(it.hasNext())
trimember test = (trimember) it.next();
if (test.last.equals(inlf[0])&&test.first.equals(inlf[1]))
results.append(test.toString()+"\n");
namefld.requestFocus();
public class trimember implements Comparable
String eTag;
public String memberNo;
public String first;
public String last;
String gender;
String yob;
String tel;
String addr;
String club;
public trimember(String eT, String me, String fi, String la,
String ge, String yo, String te, String ad, String cl)
eTag = eT;
memberNo = me;
first = fi;
last = la;
gender = ge;
yob = yo;
tel = te;
addr = ad;
club = cl;
//To String method to output string of details
public String toString()
return last + "\t" + first + "\t" + eTag + "\t" +
memberNo + "\t" + gender + "\t" + yob + "\t"+ tel + "\t" +
addr + "\t" + club;
//Compare and sort on Last name
public int compareTo(Object o)
trimember com = (trimember) o;
int lastCmp = last.compareTo(com.last);
int firstCmp = first.compareTo(com.first);
int memCmp = memberNo.compareTo(com.memberNo);
if (lastCmp == 0 && firstCmp !=0)return firstCmp;
else if (lastCmp==0&&firstCmp==0)return memCmp;
else return lastCmp;
}Edited by: Roger on Nov 3, 2007 11:50 AMPlease don't cross-post. It is considered very rude to do that here:
http://forum.java.sun.com/thread.jspa?threadID=5233033&messageID=9953169#9953169 -
How to check the value from user input in database or not?
Hello;
I want to check the value of user input from JtextFiled in my database or not.
If it is in database, then i will pop up a window to tell us, otherwise, it will tell us it is not in database.
My problem is my code do not work properly, sometimes, it tell me correct information, sometime it tell wrong information.
Could anyone help,please.Thanks
The following code is for check whether the value in database or not, and pop up a window to tell us.
while( rs.next()) {
System.out.println("i am testing");
bInt=new Integer(rs.getInt("id"));
if(aInt.equals(bInt)){ // If i find the value in data base, set flag to 1.
flag=1; //I set a flag to check whether the id in database or not
break;
System.out.println("falg" + flag);
if(flag==1){ //?????????????????????
String remove1 = "DELETE FROM Rental WHERE CustomerID=" + a;
String remove2 = "DELETE FROM Revenus WHERE CustomerID=" +a;
String remove3 = "DELETE FROM Customer WHERE id=" +a;
s.executeUpdate(remove1);
s.executeUpdate(remove2);
s.executeUpdate(remove3);
JOptionPane.showMessageDialog(null,"you have success delete the value");
s.close();
else//???????????????????????????????
JOptionPane.showMessageDialog(null,"I could not found the value"); -------------------------------------------------------------------
My whole program
import java.sql.*;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JOptionPane;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class DeleteC extends JFrame
public static int index=0;
public static ResultSet rs;
public static Statement s;
public static Connection c;
public static Object cols[][];
private static JTable table;
private static JScrollPane scroller;
private static int flag=0;
public DeleteC()
//information of our connection
//the url of the database: protocol:subprotocol:subname:computer_name:port:database_name
String strUrl = "jdbc:oracle:thin:@augur.scms.waikato.ac.nz:1521:teaching";
//user name and password
String strUser = "xbl1";
String strPass = "19681978";
//try to load the driver
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
catch (ClassNotFoundException e) {
System.out.println( "Cannot load the Oracle driver. Include it in your classpath.");
System.exit( -1);
//a null reference to a Connection object
c = null;
try {
//open a connection to the database
c = DriverManager.getConnection( strUrl, strUser, strPass);
catch (SQLException e) {
System.out.println("Cannot connect to the database. Here is the error:");
e.printStackTrace();
System.exit( -1);
//create a statement object to execute sql statements
public void getData(String a){
try {
//create a statement object to execute sql statements
s = c.createStatement();
int index=0;
Integer aInt= Integer.valueOf(a);
Integer bInt;
//our example query
String strQuery = "select id from customer";
//execute the query
ResultSet rs = s.executeQuery( strQuery);
//while there are rows in the result set
while( rs.next()) {
System.out.println("i am testing");
bInt=new Integer(rs.getInt("id"));
if(aInt.equals(bInt)){
//JOptionPane.showMessageDialog(null,"I found the value");
flag=1;
break;
System.out.println("falg" + flag);
if(flag==1){
String remove1 = "DELETE FROM Rental WHERE CustomerID=" + a;
String remove2 = "DELETE FROM Revenus WHERE CustomerID=" +a;
String remove3 = "DELETE FROM Customer WHERE id=" +a;
s.executeUpdate(remove1);
s.executeUpdate(remove2);
s.executeUpdate(remove3);
JOptionPane.showMessageDialog(null,"you have success delete the value");
s.close();
else
JOptionPane.showMessageDialog(null,"I could not found the value");
catch (SQLException e) {
JOptionPane.showMessageDialog(null,"You may enter wrong id");
My main program for user input from JTextField.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JOptionPane;
import java.util.*;
public class EnterID extends JFrame{
public JTextField tF1;
public EnterID enID;
public String tF1Value;
private JLabel label1, label2, label3;
private static JButton button;
private static ButtonHandler handler;
private static String aString;
private static Integer aInteger;
private static Integer checkV=0;
public static void main(String args[]){
EnterID eId= new EnterID();
public EnterID(){
handler=new ButtonHandler();
Container c= getContentPane();
c.setLayout(new GridLayout(3,1));
button= new JButton("ok");
button.addActionListener(handler);
label1 = new JLabel(" CustomerID, Please");
label2 = new JLabel("Label2");
label3 = new JLabel();
label3.setLayout(new GridLayout(1,1));
label3.add(button);
label2.setLayout(new GridLayout(1,1));
aString = "Enter Id Here";
tF1 = new JTextField(aString);
label2.add(tF1);
c.add(label1);
c.add(label2);
c.add(label3);
setSize(150,100);
setVisible(true);
private class ButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent event){
tF1Value=tF1.getText();
// CheckData cData = new CheckData();
// aInteger = Integer.valueOf(tF1Value);
if(tF1Value.equals(aString)){
JOptionPane.showMessageDialog(null,"You didn't type value into box");
setVisible(false);
else {
DeleteC dC= new DeleteC();
dC.getData(tF1Value);
setVisible(false);
}You may have working code now, but the code you posted is horrible and I'm going to tell you a much much much better approach for the JDBC part. (You should probably isolate your database code from your user interface code as well, but I'm skipping over that structural problem...)
Do this instead:
public void getData(String a){
PreparedStatement p;
String strQuery = "select count(*) the_count from customer where id = ?";
try {
//create a prepared statement object to execute sql statements, it's better, faster, safer
p = c.prepareStatement(strQuery);
// bind the parameter value to the "?"
p.setInt(1, Integer.parseInt(a) );
//execute the query
ResultSet rs = p.executeQuery( );
// if the query doesn't throw an exception, it will have exactly one row
rs.next();
System.out.println("i am testing");
if (rs.getInt("the_count") > 0 ) {
// it's there, do what you need to...
else
JOptionPane.showMessageDialog(null,"I could not find the value");
catch (SQLException e) {
// JOptionPane.showMessageDialog(null,"You may enter wrong id");
// if you get an exception, something is really wrong, and it's NOT user error
// always, always, ALWAYS close JDBC resources in a finally block
finally
p.close();
}First, this is simpler and easier to read.
Second, this retrieves just the needed information, whether or not the id is in the database. Your way will get much much slower as more data goes into the database. My way, if there is an index on the id column, more data doesn;t slow it down very much.
I've also left some important points in comments.
No guarantees that there isn't a dumb typo in there; I didn't actually compile it, much less test it. It's at least close though... -
How to pass user input in automator to a variable?
I want to ceate a workflow/application to
-create a new folder eg Batch001 in directory B
-grab a group of folders in directory A
-and move them to Batch001
-create an archive of Batch001
-create a new set of empty folders in directory A
I thought I had this worked out, and planned to create a small applescript to grab a user input, then pass it to a variable. Figured if I do that at the beginning I can use the variable to create the Batch folder name, which I would enter manually. There will be a number of them, but not hundreds.
I have an applescript in automator to show a dialog, but ti does not seem to pass anything to the results. Even if I just use a simple dialog no results are passed. If I run it in actionscript editor it shows a result as expected.
on run {input, parameters}
--Display Dialog and Get Input
display dialog "Batch Number?" default answer "BatchXXX"
--Get Answer & Return Comment
set input to (text returned of result)
return input
end runI tried that, but when I run my workflow, it fails and I get an error message: The action “Rename Finder Items” encountered an error.
Here are a couple of screenshots of my workflow: -
Add a actionlistener to JTextArea and print out string when the user input
Hello:
I got a problem to add a actionlistener to JTextArea and print out string which from the user input a sentence and after the user press the "enter".
Could anyone help me please?
Thanks
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.JScrollBar;
public class PanelDemo extends JFrame {
private static JTextArea tAreaUp, tAreaDown;
private BorderLayout layout;
private static String strings;
public PanelDemo()
super( " test " );
Container container = getContentPane();
layout = new BorderLayout();
container.setLayout( layout );
tAreaUp = new JTextArea(2,1);
tAreaUp.setLineWrap(true);
tAreaUp.setWrapStyleWord(true);
tAreaUp.setEditable(false);
tAreaUp.append("I am testing ");
tAreaUp.append("I am testing");
JScrollPane scrollPane = new JScrollPane(tAreaUp);
scrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setPreferredSize(new Dimension(250, 250));
tAreaDown =new JTextArea(2,1);
tAreaDown.setLineWrap(true);
tAreaDown.setWrapStyleWord(true);
tAreaDown.addActionListener(new TextAreaHandler());
JScrollPane scrollPane2 = new JScrollPane(tAreaDown);
scrollPane2.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
container.add( scrollPane, layout.CENTER );
container.add( scrollPane2, layout.SOUTH );
setSize( 300, 300 );
setVisible( true );
//private inner class for event handling
private class TextAreaHandler implements ActionListener{
//process textArea events
public void actionPerformed(ActionEvent e){
strings=e.getActionCommand();
System.out.println(strings);
public static void main( String args[] )
PanelDemo application = new PanelDemo();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}Thanks for your help, but I still got a question for you.
Do you think the way I register the even handler to the TextArea is correct?
Because the compailer complains about that which like
"D:\101\fig13_27\PanelDemo.java:43: cannot resolve symbol
symbol : method addActionListener (PanelDemo.TextAreaHandler)
location: class javax.swing.JTextArea
tAreaDown.addActionListener(new TextAreaHandler()); -
How can I have the user input two things to get result
Hi
I am trying to produce an interactive slide where the user will input two items and then receive the result.
The easiest way to describe what I am hoping to do is..........
Imagine the multipllication table and the user has to input what he wants to mulitiply ie 3 in the first text entry box and 5 in the next presses the button and the result is shown.
Now imagine the table isn't a mathematical table but a series of words across the x and y axis. The user inputs Word A, Word B and presses submit and the answer (another word) depending on the two inputs appears. There would be 12 x12 table so 144 different combinations.
Is this possible in Captivate 7?
thanks
RuthHI
There is little relationship between the two, this isn't actually the table but the same principle and shows what I am trying to acheive.
cookies
muffins
cupcakes
chicken roast
crispies
gas mark 1
great idea
gas mark 2
great idea
flapjacks
gas mark 2
gas mark 3
350 C
450F
roast potatoes
impossible
great idea
gas mark 3
450F
parsnips
great idea
350 C
gas mark 3
impossible
thanks
Ruth -
dear
i am creaintg a report, in which i am using two parameters, one parameter is from the DB while other paramter is dependant upon user input like YES or NO. I have two queries, if user enters YES then Q_1 should be executed if user enters NO then Q_2 should be executed. How can I do this in Reports, I am using Oracle Reports 9i. I tried to user BEFORE REPORT trigger but i am unable to call the query there, please help me out in writing code.
function BeforeReport return boolean is
begin
if :OPTION='YES' then
(Q_1 should be called here)
end if;
else if :OPTION='NO then
(Q_2 should be called here)
return (TRUE);
end;
Message was edited by:
qadirThanks Marcos dear
well, i am trying to understand what you suggest but not able to understand, let me jst explain you the query. Actually I am getting two inputs from user one inut is used to build a query i mean if user inputs any data it will be in WHERE clause in my select statement.
Now other input is just to show that if user inputs YES then Q_1 should be executed, if user inputs NO then Q_2 should be executed. this 2nd input has nothing to do with the database its just YES or NO. If user enters NO then this query should be executed.
SELECT STO.STO_PART PART,PAR.PAR_DESC DESCRIPTION,'('||STO.STO_CLASS||')' CLASS,
STO.STO_MINLEV "MIN LEVEL",STO.STO_MAXQTY "MAX LEVEL",STO.STO_ORDLEV "REORDER LEVEL",
STO.STO_QTY "CURRENT QUANTITY",STO.STO_ABCCLASS "ABC CLASS",STO.STO_PREFSUP "PREFERRED SUPPLIER"
FROM R5STOCK STO,R5PARTS PAR
WHERE PAR.PAR_CODE=STO.STO_PART
AND PAR.PAR_ORG=STO.STO_PART_ORG
AND STO.STO_QTY<=STO.STO_MINLEV
AND STO.STO_STORE= :STORE
AND STO.STO_MINLEV=0
AND STO.STO_MAXQTY=0
ORDER BY STO.STO_PART
otherwise if user inputs YES then
SELECT STO.STO_PART PART,PAR.PAR_DESC DESCRIPTION,'('||STO.STO_CLASS||')' CLASS,
STO.STO_MINLEV "MIN LEVEL",STO.STO_MAXQTY "MAX LEVEL",STO.STO_ORDLEV "REORDER LEVEL",
STO.STO_QTY "CURRENT QUANTITY",STO.STO_ABCCLASS "ABC CLASS",STO.STO_PREFSUP "PREFERRED SUPPLIER"
FROM R5STOCK STO,R5PARTS PAR
WHERE PAR.PAR_CODE=STO.STO_PART
AND PAR.PAR_ORG=STO.STO_PART_ORG
AND STO.STO_QTY<=STO.STO_MINLEV
AND STO.STO_STORE= :STORE
ORDER BY STO.STO_PART
i am sure you will understand now. -
Selecting user input from Select option into smart form
Hi,
when i use parameter then i wil show company code in smart-form output
but when i use select option then its throwing error parameter specified here is different
what should i do in this case i want to design a big select option screen for taking user input
REPORT ZMM.
TABLES BSEG.
DATA : V_FORMNAME TYPE TDSFNAME VALUE 'ZPUR_REG',
V_FMNAME TYPE RS38L_FNAM.
*PARAMETERS SO_BUKRS TYPE BUKRS.
SELECT-OPTIONS : SO_BUKRS FOR BSEG-BUKRS.
DATA : Z_CONTROL TYPE SSFCTRLOP, "Smart Forms: Control structure
Z_OPTIONS TYPE SSFCOMPOP. "SAP Smart Forms: Smart Composer (transfer) options.
MOVE 'X' TO : Z_control-no_dialog, "SAP Smart Forms: General Indicator
Z_options-tdnewid, "New Spool Request (Print Parameters)
z_control-PREVIEW. "Print preview
MOVE 'LP01' TO Z_options-tddest. "Spool: Output device
MOVE space TO Z_options-tdimmed. "Print Immediately (Print Parameters).
MOVE 'PRINTER' TO Z_control-device. "Output device
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
FORMNAME = V_FORMNAME
IMPORTING
FM_NAME = V_FMNAME.
CALL FUNCTION V_FMNAME
EXPORTING
CONTROL_PARAMETERS = Z_CONTROL
OUTPUT_OPTIONS = Z_OPTIONS
USER_SETTINGS = ''
BUKRS = SO_BUKRS.
pls help me in this regards.
ketan..hi
thnx for your reply
can u pls elaborate in my code
now i changed code BUKRS = SO_BUKRS-low.
either i can give low or high but how to select from range
REPORT ZMM.
TABLES BSEG.
DATA : V_FORMNAME TYPE TDSFNAME VALUE 'ZPUR_REG',
V_FMNAME TYPE RS38L_FNAM.
*PARAMETERS SO_BUKRS TYPE BUKRS.
SELECT-OPTIONS : SO_BUKRS FOR BSEG-BUKRS.
DATA : Z_CONTROL TYPE SSFCTRLOP, "Smart Forms: Control structure
Z_OPTIONS TYPE SSFCOMPOP. "SAP Smart Forms: Smart Composer (transfer) options.
MOVE 'X' TO : Z_control-no_dialog, "SAP Smart Forms: General Indicator
Z_options-tdnewid, "New Spool Request (Print Parameters)
z_control-PREVIEW. "Print preview
MOVE 'LP01' TO Z_options-tddest. "Spool: Output device
MOVE space TO Z_options-tdimmed. "Print Immediately (Print Parameters).
MOVE 'PRINTER' TO Z_control-device. "Output device
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
FORMNAME = V_FORMNAME
IMPORTING
FM_NAME = V_FMNAME.
CALL FUNCTION V_FMNAME
EXPORTING
CONTROL_PARAMETERS = Z_CONTROL
OUTPUT_OPTIONS = Z_OPTIONS
USER_SETTINGS = ''
BUKRS = SO_BUKRS-low.
ketan.. -
How to change date format of user input prompt in infoview.
Hi All,
Every report webi or deski having date field as prompt when viewed in view mode in infoview shows date format as M/d/yyyy h:mm:ss a.
Where this format is stored and how can we change it to dd/mm/yyyy.
Any ideas.
Regards,
GauravNot sure id this helps...
I was up against a similar issue of placing the user input dates, Starting & Ending, into one cell for a reference on each report header. After a few hours of diligence, I came up with a working model that finally worked:
u_StartDateAsTXT=FormatDate(ToDate(UserResponse("Enter Date/Time Shipped (Start):");"MM/dd/yyyy hh:mm:ss a");"MM/dd/yyyy")
and
u_EndDateAsTXT=FormatDate(ToDate(UserResponse("Enter Date/Time Shipped (END):");"MM/dd/yyyy hh:mm:ss a");"MM/dd/yyyy")
The report header has the following function:
=u_StartDateAsTXT + u201C u2013 u201C + u_EndDateAsTXT
Maybe you are looking for
-
Weird problem in File Adapter polling
Hi Guys, My BPEL process is working fine not until today wherein the File Adapter cannot poll for new files in the target directory. I tried restarting the bpel server and still my bpel process was not able to poll for new files. I tried creating a t
-
[SOLVED]Removing enlightenment and gnome...
Apologies if this has been posted already, I did a little search but couldn't find anything. I installed arch a couple of weeks ago with enlightenment, to me it looked by far the most advanced environment to use. However there's hardly any support! T
-
Disable editing Attributes in My Profile
Hie, does anybody know how to disable the possibility for the end user to change LDAP attributes if the Self Management is turned on? I enabled "Self Management" in "My Profile" so the User can change everything the ume is allowed to. I just want the
-
Business Rule _ RTP ,Range
Hi All, I have a req in BR where we need to specify range depending on Prompt.......Range : [FY10:FY15]...............This range should be dynamic.........users will select the start Yr.....(Its RTP).........& the 2nd member is dynamic .........it sh
-
Slowing Down/Speeding Up Loops
Sorry, nevermind, I found the answer. Message was edited by: beirut