Setting up a GUI
Is it common practice to just have one class that constructs the graphical user interface, or should I have a separate class for each panel that I add to the content pane of my main form (JFrame)? In other words, should I have a specific class that constructs each of the North, West, East, Center and South borders separately?
Thanks everyone,
Leo D
You can 'try' to create a class that extends or implements JFrame. Then, you could have a constructor that accepts an object and char type. Next, create methods that places the GUIs in the place you want. (N)orth, (S)outh, (E)ast, (W)est. This is just a skeleton and I have not tried it myself. The graphics part gets more complicated because the code just gets longer and you deal with more classes and objects.
I recently got a GUI Java compiler and my head is still spinning from trying to remember how to write code for Object-Oriented Programming. What I did before to kind of get started was take a source code example in a Java book off the CD and just modified and see what it did. That is how I learn how to implement actionlisters to graphic objects.
class myGUI extends JFrame
// - - - data members
myGUI() //default constructor
myGUI(JButton A_Button, char A_heading)
// - - - methods
North_Method()
{ Layout(North,)}
East_Method()
{ Layout(East,)}
}//end myGUI class
Similar Messages
-
How to set my own gui status when i use selection-screen
how to set my own gui status when i use selection-screen command
and
how to set the names in the application tool bar when function keys are createdMake sure that you do this in event "AT SELECTION-SCREEN OUTPUT".
Run Txn ABAPDOCU and check 'DEMO_SEL_SCREEN_STATUS' for sample.
Also check out following discussion -
Selection Screen PF-STATUS
Cheers,
Sanjeev -
Setting Up a GUI - FlowLayout - Using Two JPanels
Hello:
I am getting confused with setting up a GUI with two JPanels one that would be on top and the other middlePanel having a FlowLayout.
I set up two JPanels but obviously have something wrong because my northPanel has "disappeared" when I added a middlePanel. My componets are all over the place and again my northPanel is no longer showing.
Idea of what I'm doing.
1) Enter total number of diners
2)Confirm that diners # is correct.
3)Enter name of Diner
4)Take order - Entree (Pull-Down)
5)Two sides (CheckBox)
6)Display Completed Order of diners.
P.S. I hope my question is not too stupid I am new and has justed started Java Programming. I have tried to look through the Documentation but am getting confused with GUI relating to FlowLayout, GridLayout. etc. I'm just not sure which one I should use to set up my GUI in an organized manner. Am I on the right track or is my code completely screwed. Thanks.
** My Code **
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Menu extends JFrame {
private JTextField partyNumField, dinerName;
private JComboBox orderComboBox;
private int partyNum;
private JButton getParty, continueOrder;
private JLabel party, companyLogo, dinerLabel, entreeOrder;
private String dinnerEntree[] = {"Filet Mignon", "Chicken Cheese Steak", "Tacos", "Ribs"};
private JCheckBox mashed, cole, baked, french;
public Menu() {
super("O'Brien Caterer - Where we make good Eats!");
Container container = getContentPane();
JPanel northPanel = new JPanel();
northPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 80, 5));
companyLogo = new JLabel("Welcome to O'Brien's Caterer's");
northPanel.add(companyLogo);
party = new JLabel("Enter the Total Number in Party Please");
partyNumField = new JTextField(5);
northPanel.add(party);
northPanel.add(partyNumField);
getParty = new JButton("GO - Continue with Order");
getParty.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent actionEvent)
partyNum = Integer.parseInt(partyNumField.getText());
String ans=JOptionPane.showInputDialog(null, "Total Number is party is: "
+ partyNum + " is this correct?\n\n" + "Enter 1 to continue\n"
+ "Enter 2 to cancel\n");
if (ans.equals("1")) {
System.out.println(ans+"=continue"); // handle continue
} else { // assume to be 2 for cancel
System.out.println(ans+"=cancel"); // handle cancel
); // end Listener
northPanel.add(getParty);
JPanel middlePanel = new JPanel();
middlePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
dinerLabel = new JLabel("Please enter Diner's name");
dinerName = new JTextField(30);
continueOrder = new JButton("continue");
middlePanel.add(dinerLabel);
middlePanel.add(continueOrder);
middlePanel.add(dinerName);
entreeOrder = new JLabel("Please choose an entree");
orderComboBox = new JComboBox(dinnerEntree);
orderComboBox.setMaximumRowCount(4);
//orderComboBox.addItemListener(
// new ItemListener(){
// public void itemsStateChanged(ItemEvent event)
// if (event.getStateChange() == ItemEvent.SELECTED)
// add entree order to Person
// continue ** enable the two sides order
mashed = new JCheckBox("Mashed Potatoes");
middlePanel.add(mashed);
cole = new JCheckBox("Cole Slaw");
middlePanel.add(cole);
baked = new JCheckBox("Baked Beans");
middlePanel.add(baked);
french = new JCheckBox("FrenchFries");
middlePanel.add(french);
// CheckBoxHandler handler = new CheckBoxHandler();
// mashed.addItemListener(handler);
// cole.addItemListener(handler);
// baked.addItemListener(handler);
// french.addItemListener(handler);
middlePanel.add(entreeOrder);
middlePanel.add(orderComboBox);
container.add(northPanel);
container.add(middlePanel);
middlePanel.setEnabled(true);
setSize(500, 500);
show();
// private class to handle event of choosing Check BOx Item
// private class CheckBoxHandler implements ItemListener{
// private int count = 0;
// public void itemStateChanged(ItemEvent event){
// if (event.getsource() == mashed)
// if (event.getStateChange() == ItemEvent.SELECTED)
// count++;
// add mashed choice to person's order
// if (event.getsource() == cole)
// if (event.getStateChange() == ItemEvent.SELECTED)
// count++;
//add cole slaw to person's order
// if (event.getsource() == baked)
// if (event.getStateChange() == ItemEvent.SELECTED)
// count++;
//add baked beans to person's order
// if (event.getsource() == french)
// if (event.getStateChange() == ItemEvent.SELECTED)
// count++;
//add french to person's order
public static void main(String args[])
Menu application = new Menu();
application.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent windowEvent)
System.exit(0);
}This looks better, i myself don't like the flow layout
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Menu1 extends JFrame
private JTextField partyNumField, dinerName;
private JComboBox orderComboBox;
private int partyNum;
private JButton getParty, continueOrder;
private JLabel party, companyLogo, dinerLabel, entreeOrder;
private String dinnerEntree[] = {"Filet Mignon", "Chicken Cheese Steak", "Tacos", "Ribs"};
private JCheckBox mashed, cole, baked, french;
public Menu1()
super("O'Brien Caterer - Where we make good Eats!");
addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent ev)
dispose();
System.exit(0);
Container container = getContentPane();
JPanel northPanel = new JPanel();
northPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 120,15));
companyLogo = new JLabel("Welcome to O'Brien's Caterer's");
northPanel.add(companyLogo);
party = new JLabel("Enter the Total Number in Party Please");
partyNumField = new JTextField(5);
northPanel.add(party);
northPanel.add(partyNumField);
getParty = new JButton("GO - Continue with Order");
northPanel.add(getParty);
northPanel.setPreferredSize(new Dimension(700,150));
getParty.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent actionEvent)
partyNum = Integer.parseInt(partyNumField.getText());
String ans=JOptionPane.showInputDialog(null, "Total Number is party is: "
+ partyNum + " is this correct?\n\n" + "Enter 1 to continue\n"
+ "Enter 2 to cancel\n");
if (ans.equals("1"))
System.out.println(ans+"=continue"); // handle continue
else { // assume to be 2 for cancel
System.out.println(ans+"=cancel"); // handle cancel
}}); // end Listener
JPanel middlePanel = new JPanel();
middlePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
dinerLabel = new JLabel("Please enter Diner's name");
dinerName = new JTextField(30);
continueOrder = new JButton("continue");
middlePanel.add(dinerLabel);
middlePanel.add(dinerName);
middlePanel.add(continueOrder);
entreeOrder = new JLabel("Please choose an entree");
orderComboBox = new JComboBox(dinnerEntree);
orderComboBox.setMaximumRowCount(4);
//orderComboBox.addItemListener(
// new ItemListener(){
// public void itemsStateChanged(ItemEvent event)
// if (event.getStateChange() == ItemEvent.SELECTED)
// add entree order to Person
// continue ** enable the two sides order
mashed = new JCheckBox("Mashed Potatoes");
middlePanel.add(mashed);
cole = new JCheckBox("Cole Slaw");
middlePanel.add(cole);
baked = new JCheckBox("Baked Beans");
middlePanel.add(baked);
french = new JCheckBox("FrenchFries");
middlePanel.add(french);
// CheckBoxHandler handler = new CheckBoxHandler();
// mashed.addItemListener(handler);
// cole.addItemListener(handler);
// baked.addItemListener(handler);
// french.addItemListener(handler);
middlePanel.add(entreeOrder);
middlePanel.add(orderComboBox);
//container.add(northPanel);
//container.add(middlePanel);
container.add(northPanel, java.awt.BorderLayout.NORTH);
container.add(middlePanel, java.awt.BorderLayout.CENTER);
middlePanel.setEnabled(true);
setSize(600, 500);
show();
// private class to handle event of choosing Check BOx Item
// private class CheckBoxHandler implements ItemListener{
// private int count = 0;
// public void itemStateChanged(ItemEvent event){
// if (event.getsource() == mashed)
// if (event.getStateChange() == ItemEvent.SELECTED)
// count++;
// add mashed choice to person's order
// if (event.getsource() == cole)
// if (event.getStateChange() == ItemEvent.SELECTED)
// count++;
//add cole slaw to person's order
// if (event.getsource() == baked)
// if (event.getStateChange() == ItemEvent.SELECTED)
// count++;
//add baked beans to person's order
// if (event.getsource() == french)
// if (event.getStateChange() == ItemEvent.SELECTED)
// count++;
//add french to person's order
public static void main(String args[])
new Menu1();
no edit
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Menu1 extends JFrame
private JTextField partyNumField, dinerName;
private JComboBox orderComboBox;
private int partyNum;
private JButton getParty, continueOrder;
private JLabel party, companyLogo, dinerLabel, entreeOrder;
private String dinnerEntree[] = {"Filet Mignon", "Chicken Cheese Steak", "Tacos", "Ribs"};
private JCheckBox mashed, cole, baked, french;
public Menu1()
super("O'Brien Caterer - Where we make good Eats!");
addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent ev)
dispose();
System.exit(0);
Container container = getContentPane();
JPanel northPanel = new JPanel();
northPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 120,15));
companyLogo = new JLabel("Welcome to O'Brien's Caterer's");
northPanel.add(companyLogo);
party = new JLabel("Enter the Total Number in Party Please");
partyNumField = new JTextField(5);
northPanel.add(party);
northPanel.add(partyNumField);
getParty = new JButton("GO - Continue with Order");
northPanel.add(getParty);
northPanel.setPreferredSize(new Dimension(700,150));
getParty.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent actionEvent)
partyNum = Integer.parseInt(partyNumField.getText());
String ans=JOptionPane.showInputDialog(null, "Total Number is party is: "
+ partyNum + " is this correct?\n\n" + "Enter 1 to continue\n"
+ "Enter 2 to cancel\n");
if (ans.equals("1"))
System.out.println(ans+"=continue"); // handle continue
else { // assume to be 2 for cancel
System.out.println(ans+"=cancel"); // handle cancel
}}); // end Listener
JPanel middlePanel = new JPanel();
middlePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
dinerLabel = new JLabel("Please enter Diner's name");
dinerName = new JTextField(30);
continueOrder = new JButton("continue");
middlePanel.add(dinerLabel);
middlePanel.add(dinerName);
middlePanel.add(continueOrder);
entreeOrder = new JLabel("Please choose an entree");
orderComboBox = new JComboBox(dinnerEntree);
orderComboBox.setMaximumRowCount(4);
//orderComboBox.addItemListener(
// new ItemListener(){
// public void itemsStateChanged(ItemEvent event)
// if (event.getStateChange() == ItemEvent.SELECTED)
// add entree order to Person
// continue ** enable the two sides order
mashed = new JCheckBox("Mashed Potatoes");
middlePanel.add(mashed);
cole = new JCheckBox("Cole Slaw");
middlePanel.add(cole);
baked = new JCheckBox("Baked Beans");
middlePanel.add(baked);
french = new JCheckBox("FrenchFries");
middlePanel.add(french);
// CheckBoxHandler handler = new CheckBoxHandler();
// mashed.addItemListener(handler);
// cole.addItemListener(handler);
// baked.addItemListener(handler);
// french.addItemListener(handler);
middlePanel.add(entreeOrder);
middlePanel.add(orderComboBox);
//container.add(northPanel);
//container.add(middlePanel);
container.add(northPanel, java.awt.BorderLayout.NORTH);
container.add(middlePanel, java.awt.BorderLayout.CENTER);
middlePanel.setEnabled(true);
setSize(600, 500);
show();
// private class to handle event of choosing Check BOx Item
// private class CheckBoxHandler implements ItemListener{
// private int count = 0;
// public void itemStateChanged(ItemEvent event){
// if (event.getsource() == mashed)
// if (event.getStateChange() == ItemEvent.SELECTED)
// count++;
// add mashed choice to person's order
// if (event.getsource() == cole)
// if (event.getStateChange() == ItemEvent.SELECTED)
// count++;
//add cole slaw to person's order
// if (event.getsource() == baked)
// if (event.getStateChange() == ItemEvent.SELECTED)
// count++;
//add baked beans to person's order
// if (event.getsource() == french)
// if (event.getStateChange() == ItemEvent.SELECTED)
// count++;
//add french to person's order
public static void main(String args[])
new Menu1();
} -
Can't see the logical system set up via Gui PI while build up business syst
Hi all:
I set up a logical ssytem via Sale via PI Gui----ECC800, but when build up
business systems ECC800, I cann't see ECC800. it seems that we need to
synchronise it through Gateway, Could you please tell me how in detail?
Thank you very much!!!Unfortunately, it seems that Toahiba has not improved their driver releases. As they repackage the nVidia drivers, a straight nVidia driver will seldom install properly. I had a Toshiba Satellite (biggest, baddest in its day), and it never got a video driver update. No nVidia drivers would install. I found this Web site, and for the five years that I used that laptop, it rewrapped every new nVidia driver, to install on the Toshiba: http://www.laptopvideo2go.com/drivers.
Predicated on a similar Toshiba thread, I checked for that old Satellite, and Toshiba had not issued a new one, four years later - so their one driver was about 9 years old at that point.
Good luck,
Hunt -
Default setting of SAP GUI Status bar
Hello all,
Is there a way to set a default value of the precious combobox from the GUI status bar (the one showing System, Client, User, Program.....).
I would like to set it to always display the SAP System.
thanks.Hi,
you can do this like below.
First select the option to show 'System' ( may be it is by default prompting to show 'Program Name' )
next time when you login it will default with System name only.
Kind Regards,
Ravi Sankar.Z -
Setting up a gui and the actionlisteners..?
hi... i am new to java...so this might be a stupid question ...this is w i did until now:
import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.JPanel;
import javax.swing.border.*;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import java.awt.event.*;
public class menuepanel extends JPanel
public menuepanel()
Border rille = BorderFactory.createEtchedBorder();
setBorder(rille);
public menuepanel(String text)
ImageIcon symbol = new ImageIcon("Smiley.jpg");
setLayout(new GridLayout(24,0));
JButton regel = new JButton("Regeln");
regel.setBackground(Color.darkGray);
regel.setForeground(Color.white);
regel.setMnemonic('r');
add(regel);
JButton histo = new JButton("History");
histo.setBackground(Color.darkGray);
histo.setForeground(Color.white);
histo.setMnemonic('h');
add(histo);
JButton hisco = new JButton("Highscore");
hisco.setBackground(Color.darkGray);
hisco.setForeground(Color.white);
hisco.setMnemonic('s');
add(hisco);
JButton mstart = new JButton("M�hle Starten");
mstart.setBackground(Color.darkGray);
mstart.setForeground(Color.white);
mstart.setMnemonic('m');
add(mstart);
JButton exc = new JButton("Spiel abbrechen");
exc.setBackground(Color.darkGray);
exc.setForeground(Color.white);
exc.setMnemonic('a');
add(exc);
JButton test = new JButton("test");
test.setBackground(Color.darkGray);
test.setForeground(Color.white);
test.setMnemonic('t');
add(test);
JButton exit = new JButton("Fenster schlie�en");
exit.setBackground(Color.darkGray);
exit.setForeground(Color.white);
exit.setMnemonic('f');
exit.setActionCommand("exit");
add(exit);
my question is:
what do i have to do now to get an action if i hit a button?
could some1 give me a short example, like how the code should look if i want the gui-window to be close when hitting the exit-button?
please help
pfffimport java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;
class menuepanel extends JPanel implements ActionListener
String[] buttonText = {"Regeln","History","Highscore","M�hle Starten",
"Spiel abbrechen","test","Fenster schlie�en"};
char[] mnemonic = {'r','h','s','m','a','t','f'};
JButton[] btn = new JButton[buttonText.length];
public menuepanel()
Border rille = BorderFactory.createEtchedBorder();
setBorder(rille);
setLayout(new GridLayout(7,1));
for(int x = 0; x < btn.length; x++)
btn[x] = new JButton(buttonText[x]);
btn[x].setBackground(Color.darkGray);
btn[x].setForeground(Color.white);
btn[x].setMnemonic(mnemonic[x]);
btn[x].addActionListener(this);
add(btn[x]);
public void actionPerformed(ActionEvent ae)
if(ae.getActionCommand().equals(buttonText[buttonText.length-1])) System.exit(0);
class MainApplication extends JFrame
public MainApplication()
setLocation(400,300);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
getContentPane().add(new menuepanel());
pack();
public static void main(String[] args){new MainApplication().setVisible(true);}
} -
Need HELP setting colors in GUI
hi iam trying to write a program that allows you to check the color red green or blue once you selected your color and click the button i created its suppose to display the color what i have done so far gives a problem i think its simple but i just cant seem to find it thats why its so frustrating but when i select a color and press show it only gives me black regardless of what color is choosen if anyone can take a look at my code and give me some kind of feedback that would be great thanks
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
public class colorFrame extends JFrame
implements ActionListener{
//check boxes
private JCheckBox jRed = new JCheckBox("RED");
private JCheckBox jGreen = new JCheckBox("GREEN");
private JCheckBox jBlue = new JCheckBox("BLUE");
//Radio buttons
private JRadioButton jLight = new JRadioButton("Light");
private JRadioButton jNormal = new JRadioButton("Normal");
private JRadioButton jDark = new JRadioButton("Dark");
//Buttons
private JButton jShow = new JButton("Show");
//Display area
private JPanel JColor = new JPanel();
float blue, green, red;
//Main Method
public static void main(String[] args){
colorFrame frame = new colorFrame();
frame.setTitle("Color Frame");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600,400);
frame.setVisible(true);
public colorFrame(){
//get the content pane of the frame
Container container = getContentPane();
//set flowlayout
container.setLayout(new BorderLayout());
//create panel check set grid
JPanel check = new JPanel();
check.setLayout(new GridLayout(1,3)) ;
//add check boxes
check.add(jRed);
check.add(jGreen);
check.add(jBlue);
//Create panel radio set grid
JPanel radio = new JPanel();
radio.setLayout (new GridLayout(1,3));
//Add radio buttons
radio.add(jLight);
radio.add(jNormal);
radio.add(jDark);
//Create panel button
JPanel button = new JPanel();
button.setLayout (new GridLayout());
//add button
button.add(jShow);
//Create panel to show color
JColor.setLayout (new GridLayout());
Dimension d = new Dimension(400,300);
JColor.setPreferredSize(d);
//Test panel
JPanel p5 = new JPanel();
p5.setLayout (new GridLayout(2,3));
//add registers
jShow.addActionListener(this);
jRed.addActionListener(this);
jBlue.addActionListener(this);
jGreen.addActionListener(this);
jNormal.addActionListener(this);
jDark.addActionListener(this);
jLight.addActionListener(this);
//add panels
p5.add (check, BorderLayout.SOUTH);
p5.add (radio, BorderLayout.SOUTH);
//p5.add(button, BorderLayout.EAST);
//Add panels to frame
//container.add(check, BorderLayout.SOUTH);
//container.add(radio, BorderLayout.SOUTH);
container.add(button, BorderLayout.EAST);
container.add(JColor, BorderLayout.NORTH);
container.add(p5, BorderLayout.SOUTH);
public void actionPerformed(ActionEvent e) {
if(e.getSource() == jShow){
if (e.getSource() == jRed){
jRed.isSelected();
red = 1.0f;
green = 0.0f;
blue = 0.0f;
if (e.getSource() == jGreen){
jBlue.isSelected();
red = 0.0f;
green = 1.0f;
blue = 0.0f;
if (e.getSource() == jBlue){
jBlue.isSelected();
red = 0.0f;
green = 0.0f;
blue = 1.0f;
Color newColor = new Color(red, green, blue);
JColor.setBackground(newColor);
}Okay here's some feedback first of all your
explanation of what you are trying to do and what
happens is hardly readable because you don't use
sentences and people will prolly just skim over it
just for that reason and right they are to continue
you should be congratulated for using code tags that
does help a lot now your code would be a lot more
readable if you followed standard conventions like
not starting class names with lowercase and not
starting variable names like fields with an uppercase
such as JColor and finally you should not have your
frame be its own actionlistener you should create a
separate (anonymous inner class) instance of a
listener for each component when you have done all
this (and your problem isn't fixed yet) please come
back you're welcome.well im sorry u had a hard time reading it next time i will type slower for you OK i asked for help not your stupid comments and i would like to say thank you KAJ moving the ifs out worked thank you -
Hi,
I'm wondering how I can set the default locale so I'll be able to enter dates etc using my local format ?You can configure the values for the session (ALTER SESSION), perhaps using a trigger on connect.
See:
Re: Alter session command on start-up -
I hate using the swing layout managers, but i would like to make my components to change in size when the window is resized. I currently use websphere which is based on eclipse (the visual editor). Any experience with tools that work well for you? thanks.
You can take a look at the FreeLayout that
comes with NetBeans 5.0 Its a real cool one, and is
available as a separate jar file.Thanks, after some searching I think your refering to the Matisse Project?
http://www.netbeans.org/kb/articles/matisse.html
I'll check it out, im downloading the netbeans ide right now. -
ActionEvent/Setting gui text in an infinite loop
Hi,
I have set up a gui that contains ~ 100 JTextFields and one JTextButton
Pressing the JTextButton on the gui triggers an action event that
1. establishes a socket connection w/ a server
2. reads input from the server in an infinite loop
3. should use the server data to dynamically setText in the various JTextFields found on the gui.
for example, during one iteration of the infinite loop, the data may set the text of JTextField #1 to ?foo? and in a later iteration of the loop, the new data from the input stream may set the text of the same field to something else (e.g. ?bar?). Thus, the gui should show a dynamically changing collection of TextFields after the user presses the JTextButton.
Problem: because of the infinite loop, NONE of the fields is ever updated (see pseudocode below). If I remove the infinite loop and simply have 1 iteration of the block of code within the actionPerformed method, the gui updates properly.
How might I alter the code to a) maintain the server connection, b) continuously read from the input stream and c) have a dynamic update of the textfields w/in the gui?
I've tried adding "this.paint(this.getGraphics());" within the infinite loop and it sort of works, but the updates to the gui are FAR SLOWER than the data that are streaming in from the server.
Thanks for any help!
The code looks something like this
Public class abc extends JFrame
Public abc()
{initialize components}
instantiate all textfields & button
create various arrays
public void initialize components
(set up gui using gridbaglayout
add actionListener to button)
private actionperformed
(establish socket connection w/ server
read data from server in an infinite loop
parse data and use information to setText on the gui)
public static void main(blah blah)
show abc();have the reading loop in a different class which will have its own Thread running aside from the main program's thread. This way your application will do both at once :)
-
Tell me the perameter to set maximum gui auto logout time for limited users
hi gurus...
i want to know the perameter to set the maximum gui auto logout time for limited users...
at present i have auto logout time as 30 minutes..but i need to set the value as 10 minutes for some group of user...
if any one know any perameter plz let me know..
thanks in advance,
chaitanya...Hi Chaitanya,
I don't think theres a specific parameter to achieve this, but you can set the value of rdisp/gui_auto_logout to 10 in one of the instances and create a new logon group for this users.
Hope this help!
Juan
Please reward with points if helpful -
Setting GUI elements not displaying and SwingWorkers....
I have a prototype JMS application where a JMS message handler class wraps a GUI application class. Updates are made from the wrapper class to the HMI via a public method on the GUI which then sets the numerous GUI elements. The element values are set but the display is not updated. From what I have read this is a common situation where within the GUI class the updating method should use a SwingWorker to carry out the work and to coordinate the threads. Given that this approach is not working would anyone have any suggestions as to how I can resolve this.
Thanks
CYou can use SwingUtilities.invokeLater(...) to update the state of a GUI component.
-
GUI to set file, other class to read it, file null error
Perhaps not the most informative subject for this problem. I have a GUI in which a file chooser is used to select a file to be read. Another class reads in this file, and goes on to process it. My main class sets up the GUI and then goes on to process the files in the second class.
I am having trouble, I believe, with timing. The main class sets up the GUI, it runs perfectly, and then I catch a problem (that will evolve into an error), where the file I am supposed to process is null, because I have not had a chance to use the file chooser in the GUI. I haven't had any luck finding a solution online, although if there is one (or another tutorial I missed), please feel free to pass the link(s) along. I am posting the relevant code below.
Thanks,
Danielle
public Main()
* @param args the command line arguments
public static void main(String[] args)
javax.swing.SwingUtilities.invokeLater(new Runnable()
public void run()
System.out.println("About to run create GUI method");
MGui app = new MGui();
System.out.println("declared a new MGui....");
app.createAndShowGUI();
/**Starting to get file choices and moving them into GPR Handler:
GprHandler gpr = new GprHandler();
//~ System.out.println("should be perfect????");
// }//end if
}// end main(String[] args)
}// end class MainThe GUI uses the following code for the file chooser:
private class enterFile2Action implements ActionListener
public void actionPerformed(ActionEvent evt)
JFileChooser chooser = new JFileChooser();
int rVal = chooser.showOpenDialog(enterFile1);
if(rVal == JFileChooser.APPROVE_OPTION)
inputFile2 = chooser.getSelectedFile();
PrintWriter outputStream;
file2Name = inputFile2.getName();
enterLabel2.setText(file2Name);
}Finally, the GprHandler class processes the file- reading it and such. The only relevant method, however is below.
/** taking in files*/
public boolean readFiles()
boolean nullFiles = true;
System.out.println("into method readFiles()");
if (MGui.get1Name() != null)
System.out.println("name isn't null");
file1Name = MGui.get1Name();
file1 = new File(file1Name);
if (MGui.get2Name() != null)
file2Name = MGui.get2Name();
file2 = new File(file2Name);
nullFiles = false;
}//end if
if (nullFiles)
System.out.println("one or more files is undeclared");
return false;
}//end if
else
try{
file1Reader = new FileReader(file1);
file2Reader = new FileReader(file2);
}//end try
catch (FileNotFoundException e)
System.out.println("file not found exception");
return false;
} //end catch
}//end else
return true;
}No, you're quite right. I want the GprHandler to
start when I've got something there for it to start
with. I never thought to call it from the
actionPerformed though. I think I've been listening
to too many lectures on some prof's definition of a
"proper main class".
I think I understand what you're suggesting: I
should simply remove the GprHandler part from my main
class and place it instead in the actionPerformed
methods, once the files are actually named/chosen.
Did I get that right?
Qualified yes. Does GPRHandler implement Runnable? I mean you don't want to do the processing in the swing event thread. So what you should do is in the actionPerformed create the Handler (with the file or whatever other bits it needs) and then start it.
Then it can process merrily along in a seperate thread. -
Can you save a GUI configuration??
Hi everyone,
I am learning java and have a question.
I have a jdesktop pane and it has multiple internal frames in it. Now I open a bunch of frames and place it the way I want.
Now can I do something like save this configuration in any file say for example an XML file and then when i open the program again I can just load the configuration file and everything comes back the same way it was when i had saved it.
Is this possible if yes then how will I be able to do it???
Here is the code which I using to display my internal frames.
//Import files
public class InternalFrameDemo extends JFrame implements ActionListener {
JDesktopPane desktop;
public InternalFrameDemo() {
super("DashBoard");
//Make the big window be indented 50 pixels from each edge
//of the screen.
int inset =250;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(inset, inset,
screenSize.width - inset*2,
screenSize.height - inset*2);
//Set up the GUI.
desktop = new JDesktopPane(); //a specialized layered pane
setContentPane(desktop);
setJMenuBar(createMenuBar());
desktop.setBackground(Color.lightGray);
//Make dragging a little faster but perhaps uglier.
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
protected JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar();
//Set up the lone menu.
JMenu menu = new JMenu("NEW");
menu.setMnemonic(KeyEvent.VK_D);
menuBar.add(menu);
//Set up the first menu item.
JMenuItem menuItem = new JMenuItem("LED Panel");
menuItem.setMnemonic(KeyEvent.VK_L);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_L, ActionEvent.ALT_MASK));
menuItem.setActionCommand("new");
menuItem.addActionListener(this);
menu.add(menuItem);
//Set up the second menu item.
JMenuItem menuItem2 = new JMenuItem("Digital Clock");
menuItem2.setMnemonic(KeyEvent.VK_D);
menuItem2.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_D, ActionEvent.ALT_MASK));
menuItem2.setActionCommand("new2");
menuItem2.addActionListener(this);
menu.add(menuItem2);
//Set up the Third menu item.
JMenuItem menuItem3 = new JMenuItem("Analog Clock");
menuItem3.setMnemonic(KeyEvent.VK_A);
menuItem3.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_A, ActionEvent.ALT_MASK));
menuItem3.setActionCommand("new3");
menuItem3.addActionListener(this);
menu.add(menuItem3);
//Set up the Fourth menu item.
JMenuItem menuItem4 = new JMenuItem("Signal Levels");
menuItem4.setMnemonic(KeyEvent.VK_S);
menuItem4.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_S, ActionEvent.ALT_MASK));
menuItem4.setActionCommand("new4");
menuItem4.addActionListener(this);
menu.add(menuItem4);
//Set up the fifth menu item.
JMenuItem menuItem5 = new JMenuItem("GPS Status");
menuItem5.setMnemonic(KeyEvent.VK_G);
menuItem5.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_G, ActionEvent.ALT_MASK));
menuItem5.setActionCommand("new5");
menuItem5.addActionListener(this);
menu.add(menuItem5);
//Set up the Quit menu item.
menuItem = new JMenuItem("Quit");
menuItem.setMnemonic(KeyEvent.VK_Q);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_Q, ActionEvent.ALT_MASK));
menuItem.setActionCommand("quit");
menuItem.addActionListener(this);
menu.add(menuItem);
return menuBar;
//React to menu selections.
public void actionPerformed(ActionEvent e) {
if ("new".equals(e.getActionCommand())) { //new
createFrame();
} else if("new2".equals(e.getActionCommand())) {
createButtons();
}else if ("new3".equals(e.getActionCommand())){
createAnalog();
}else if ("new4".equals(e.getActionCommand())){
createBoxes();
}else if ("new5".equals(e.getActionCommand())){
createGPS();
else{
quit();
protected void createFrame() {
MyInternalFrame frame = new MyInternalFrame();
TestApplet clock = new TestApplet();
clock.init();
frame.getContentPane().add(clock);
frame.setSize(150, 150);
frame.setVisible(true); //necessary as of 1.3
desktop.add(frame);
try {
frame.setSelected(true);
} catch (java.beans.PropertyVetoException e) {}
protected void createAnalog() {
MyInternalFrame frame = new MyInternalFrame();
AnalogClock clock = new AnalogClock();
frame.getContentPane().add(clock);
frame.setSize(180, 200);
frame.setVisible(true); //necessary as of 1.3
desktop.add(frame);
try {
frame.setSelected(true);
} catch (java.beans.PropertyVetoException e) {}
protected void createBoxes() {
//Code
protected void createButtons(){
MyInternalFrame frame = new MyInternalFrame();
final DigitalClock dc = new DigitalClock();
dc.setBackground(Color.black);
frame.getContentPane().add(dc);
frame.setSize(290, 120);
frame.setVisible(true); //necessary as of 1.3
desktop.add(frame);
class Task extends TimerTask {
public void run() {
dc.repaint();
java.util.Timer timer = new java.util.Timer();
timer.schedule(new Task(),0L,250L);
try {
frame.setSelected(true);
} catch(java.beans.PropertyVetoException e) {}
protected void createGPS() {
MyInternalFrame frame = new MyInternalFrame();
gpsstatus clock = new gpsstatus();
frame.getContentPane().add(clock);
frame.setSize(300, 190);
frame.setVisible(true); //necessary as of 1.3
desktop.add(frame);
try {
frame.setSelected(true);
} catch (java.beans.PropertyVetoException e) {}
//Quit the application.
protected void quit() {
System.exit(0);
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window.
InternalFrameDemo frame = new InternalFrameDemo();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Display the window.
frame.setVisible(true);
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}FanJava wrote:
Hi everyone,
I am learning java and have a question.
I have a jdesktop pane and it has multiple internal frames in it. Now I open a bunch of frames and place it the way I want.
Now can I do something like save this configuration in any file say for example an XML file and then when i open the program again I can just load the configuration file and everything comes back the same way it was when i had saved it.yes.
Is this possible if yes then how will I be able to do it???you need to design your GUI using absolute layout--null layout manager, that way you can specify how big and exactly where you want all of your components. -
Challenge involving creating a file on GUI & seeing one record at a time...
Hi,
If anyone can help me with this project I'd be most appreciative. I'll try and explain the problem the best I can. I'm adding students to a database at a university they're either a Graduate or an Undergraduate. I'm taking in first, lastname's, ssn, & ACT/SAT/GMAT test results. I have a GUI called StudentRecord that has all the JTextFields, JButton's, etc. I'm also writing it to a .txt file called StudentDA. For this I used a BufferedFile reader.
What I really need is on my StudentRecord when I click the display button I want it to show one record at a time in another JFrame. This other JFrame I named it display. I'm trying to create an instance of JFrame inside of the actionPerformed for StudentRecord but when I click display nothing happens.
I adding the students with a vector that I'm calling v. I want the Display to read from the .txt file and display one at a time hence next, and previous. I'm going to post the tidbit of relevant code. If anyone can help me you'd be my hero for the day for all time I've tried to get this to work.
Here's the StudentRecord (GUI) display part:
public void actionPerformed( ActionEvent event )
try {
Display d = new Display(StudentDA.v);
}//end try
//catch right here no problems with this..Here's the DataAccess part:
public class StudentDA{
static Vector v = new Vector();;
static String pathName = "a:/Final Project/test1.txt";
static File studentFile = new File(pathName);
static String status;
public StudentDA() {}
public static void initialize() {
if (studentFile.exists() && studentFile.length() !=0) {
try{
BufferedReader in = new BufferedReader(new
FileReader(studentFile) );
do{
status = in.readLine();
if(status.equals ("uGrad")) {
uGrad u = new uGrad();
u.setFName(in.readLine() );
u.setLName(in.readLine() );
u.setssNum(Integer.parseInt(in.readLine()) );
u.setACT(Integer.parseInt(in.readLine() ));
v.add(u);
System.out.println(u + "inside ugrad");
}//end if uGrad
else{
if(status.equals("Grad")) {
//same process as uGrad
v.add(g);
}//end else Grad
}while (status != null);
}//end try statement
catch (Exception e) {
}//end catch
}//end if there's something there
}//end method initialize
//creating the terminate method
public static void terminate() {
try{
PrintStream out = new PrintStream ( new
FileOutputStream (studentFile) );
for (int i = 0; i < v.size(); i++) {
Student s = (Student) v.elementAt(i);
String p = s.printRecord();
StringTokenizer rt = new StringTokenizer(p, "\t");
while (rt.hasMoreTokens() ) {
out.println(rt.nextToken() );
}//end while
}//end for loop
}//end try loop
catch (Exception e){
}//end catch
}//end terminate
public static void add(Student s){// throws DuplicateException{
boolean duplicate = false;
for(int i = 0; i < v.size(); i++){
if(s.getssNum() == ((Student)(v.elementAt(i))).getssNum()){
duplicate = true;
break;
if(duplicate){
throw new DuplicateException("Student Already Exists");
else{
v.add(s);
}//end add method
}//end classHere's the display class:
public class Display extends JFrame {
private JButton Next, Previous;
private JTextField statusField, firstField, lastField, socialField, advPlacementField, actField;
private JLabel statusLabel, firstLabel, lastLabel, socialLabel, advPlacementLabel, actLabel;
private JPanel fieldPanel, buttonsPanel;
private JTextArea displayArea;
static int count = 0;
static String status;
public Display(){}
public Display(Vector v){
//setting up the GUI components for the display class here
//JTextAreas & JLabels
buttonsPanel = new JPanel();
buttonsPanel.setLayout(new GridLayout(1,2));
Next = new JButton("Next");
buttonsPanel.add(Next);
Next.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent event )
//try to catch display errors
try {
count++;
displayData(count);
//displayData();
}//end try
catch {
}//end catch
} // end actionPerformed
} // end anonymous inner class
); // end call to addActionListener
buttonsPanel.add(Next);
Previous = new JButton("Previous");
buttonsPanel.add(Previous);
Previous.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent event )
//try to catch display errors
try {
count--;
displayData(count);
//displayData();
}//end try
catch {
}//end catch
} // end actionPerformed
} // end anonymous inner class
); // end call to addActionListener
}//end display() constructor
public void displayData(int count) {
StudentDA.initialize();
if (status.equals ("uGrad")) {
//these are all part of the StudentRecord GUI not Display GUI
fieldPanel.setVisible(true);
buttonsPanel.setVisible(true);
actLabel.setVisible(true);
actField.setVisible(true);
advPlacementLabel.setVisible(false);
advPlacementLabel.setVisible(false);
}//end if
else {
if(status.equals ("Grad")) {
fieldPanel.setVisible(true);
buttonsPanel.setVisible(true);
actLabel.setVisible(false);
actField.setVisible(false);
advPlacementLabel.setVisible(true);
advPlacementLabel.setVisible(true);
}//end if
}//end else
}//end method displayData()
public static void main ( String args[] )
Display application = new Display();
application.addWindowListener(
new WindowAdapter(){
public void windowClosing( WindowEvent e)
System.exit(0);
application.setSize( 300, 200);
application.setVisible( true );
};//end main
}//end class Display{}I know this is long but if anyone can help I'd greatly appreciate it. Please ask me if you need me to clarify something, I tried to not make it way too long. --rockbottom01
I'm not really too sure what it is that you are after, but here is some code, that loads up an array with each line of a .txt file, then displays them. I hope you can make use of a least some of it.
just ask if you don't understand any of the code.
String array[];
int i;
public Test() {
readFile("file.txt");
i = 0;
nextEntry();
public void nextEntry() {
Display display = new Display();
display.show();
class Display extends JFrame implements ActionListener {
JLabel label1;
JButton button;
public Display() {
label1 = new JLabel(array);
button = new JButton("OK");
getContentPane().setLayout(new FlowLayout());
getContentPane().add(label1);
getContentPane().add(button);
button.addActionListener(this);
public void actionPerformed(ActionEvent e) {
setVisible(false);
i++;
if(i < array.length) {
nextEntry();
public void readFile(String fileName) {
String s, s2 = "";
int lineCount = 0;
BufferedReader in;
try {
in = new BufferedReader(new FileReader(fileName));
while((s = in.readLine()) != null) {
lineCount++;
array = new String[lineCount];
in.close();
in = new BufferedReader(new FileReader(fileName));
int j = 0;
while((s = in.readLine()) != null) {
array[j] = s;
j++;
catch(IOException e) {
System.out.println("Error");
Maybe you are looking for
-
Hi Experts, We are working in SRM 5.0 classic schenario. We have made some settings in transaction 'bbpctol', and afterwards allocated the tolerance group in PPOMA_BBP. Problem: Now I would like to use the tolerance settings from back end, R/3. For t
-
Hi Experts, I have faced one problem in Mail Triggering. to the User. Our Requirement is, Whenever we execute one report ( ALV output) in Background , The Output should go the user thro mail ( automatic Mail trigger w
-
Problems with X-Fi Elite Pro's I/O Breakout R
I'm thinking this might largely be a power supply problem, but it might also be a faulty rack. The card works and I get sound. I've also plugged in the power supply to the sound card in order to get the I/O box to work. After I install the drivers (I
-
Row level trigger updating the entire table instead of affected rows
I am using orace 8.1.7. My problem is I have a row level trigger that should fire only once ( and insert a row in my auditing table). But it is doing it for the entire table. This only happens when I have more than two columns in an Update clause. Ha
-
Anyone heard of a wash transition? I have been asked to use one by a client but I have not heard of this transition option before.