Calling method to add JFrame components
I'm trying to build a GUI. I have a JFrame and want to add components to it from their individual classes to keep everything seperate.
Can someone give me some guidance with the call?
Frame.add(method from other class)
I'm not sure how to do this. I've tried several different options and attempts, but I can't get the syntax right. I can do it from within the JFrame class, but can't figure out the external call. All the examples and tuts I find show calls within the same class, but not from other classes. Right now that's my weak point with this.
Any guidance...
Thanks in advance
public class MyComponent{
public JButton createLabel(String caption){
return new JButton(caption);
public JPanel createPanel(){
JPanel p = new JPanel();
p.add(new JScrollPane(new JTextArea()));
return p;
public class Demo{
public Demo(){
MyCompoent c = new MyComponet();
JFrame frame = new JFrame();
// note: if you're using 1.4.2 or older...you have to do
// frame.getContentPane().add(component, position);
// JFrame by default uses a BorderLayout, to change layout..use setLayout() method
frame.add(c.createPanel(), "Center");
frame.add(c.createButton("Exit"), "South");
frame.pack();
frame.setVisible(true);
}
Similar Messages
-
Searching for class or method to add mobile components programatically
Hello,
I'm searching for a class and/or a method to add a mobile component and version to a mobile device programatically.
Furthermore I would like to know in which datbase-table I can find
a) The roles and their mobile components
b) The installed components of the registered devices.
I Hope you can help me with this issue.
Best regards.
LarsHello,
thanks for your responses. I think the answer of Shobha is very good. I've found a second solution for this problem.
1. Set the MCD-Attributes
DATA: mcd_name TYPE SMMW_MCDNAME,
mcd_ver TYPE SMMW_MCDVERSION.
CLEAR mcd.
mcd-MCDNAME = mcd_name.
mcd-VERSION = mcd_ver.
APPEND mcd TO mcds.
CLEAR mcd.
2. Call method
CALL METHOD CL_SMMW_DEV_ADM=>ASSIGN_MCD_TO_DEVICE
EXPORTING
RECEIVERID = 'Your receiver-ID'
MCDS = mcds
AUTO_FLAG = 'X'
INVOKE_RULE_EVALUATION = 'X'
IMPORTING
NON_AVAIL = NON_AVAIL
FAILED_MCDS = FAILED_MCDS
MESSAGE_RETURN = MESSAGE_RETURN
EXCEPTIONS
MCDNAME_VERSION_INCOMPLETE = 1
others = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
With the method of class CL_SMMW_DEV_ADM you can easily add MCDs to your device.
Thank you for your help.
Best regards.
Lars -
Call method after closing JFrame
Hi everyone,
I'm opening a JFrame in another JFrame.
Here is the code and beneath is the question.
import javax.swing.*;
import javax.swing.text.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;
public class ContactsInterface extends JFrame implements ActionListener
JList contactList;
private DefaultListModel listModel;
JPanel buttonPanel;
JPanel detailsPanel;
JButton addButton, updateButton, deleteButton, refreshButton;
JLabel companyLabel;
JTextField companyField;
public ContactsInterface()
super("ContactList");
listModel = new DefaultListModel();
contactList = new JList(listModel);
buttonPanel = new JPanel();
detailsPanel = new JPanel();
addButton = new JButton("Add Record");
addButton.addActionListener(this);
updateButton = new JButton("Update Record");
updateButton.addActionListener(this);
deleteButton = new JButton("Delete Record");
deleteButton.addActionListener(this);
refreshButton = new JButton("Refresh");
refreshButton.addActionListener(this);
companyLabel = new JLabel(" Company:");
companyField = new JTextField(10);
companyField.setEditable(false);
buttonPanel.setLayout(new FlowLayout());
detailsPanel.setLayout(new GridLayout(6,2,10,10));
buttonPanel.add(addButton);
buttonPanel.add(updateButton);
buttonPanel.add(deleteButton);
buttonPanel.add(refreshButton);
detailsPanel.add(companyLabel);
detailsPanel.add(companyField);
setLayout(new BorderLayout());
JScrollPane contactJScroll = new JScrollPane();
contactJScroll.setPreferredSize(new Dimension(100,80));
contactJScroll.getViewport().setView(contactList);
add(contactJScroll, BorderLayout.WEST);
add(buttonPanel, BorderLayout.SOUTH);
add(detailsPanel, BorderLayout.CENTER);
public void actionPerformed(ActionEvent e)
String args = e.getActionCommand();
if(args.equals("Add Record"))
openAddRecord();
public static void main(String args[]) //main method of the ContactsInterface
ContactsInterface CInterface = new ContactsInterface();
CInterface.setJMenuBar(CInterface.createMenuBar());
CInterface.setDefaultCloseOperation(EXIT_ON_CLOSE);
CInterface.setSize(500,300);
CInterface.setVisible(true);
CInterface.setResizable(false);
public void openAddRecord() // The method being called when clicking Add record which in turn opens another JFrame on top of the ContactsInterface JFrame
record = new AddRecord();
record.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
record.setVisible(true);
record.setResizable(false);
record.setSize(400,300);
public void refreshList(String company) //The method that needs to be called when disposing of the openAddRecord JFrame
listModel.addElement(company);
int index;
index = contactList.getLastVisibleIndex();
index++;
contactList.setSelectedIndex(index);
contactList.ensureIndexIsVisible(index);
}The "openAddRecord Frame" opens fine, in the "openAddRecord JFrame" I add a company name.
How can I when I click on the "Save" button in the "openAddRecord JFrame" and then dispose(); of the "openAddRecord JFrame" let it call a method in the "ContactsInterface JFrame" which was the parent of "openAddRecord JFrame" / were the "openAddRecord JFrame" was opened in, to refresh the JList by calling the "refreshList" method.Don't use multiple JFrames.
A typical application will only ever have a single JFrame. If you need a second window you would use a JDialog. If you want to stop execution until the dialog is closed then you would use a "modal" JDialog. -
I have a program that has several statements starting with this CALL_METHOD_* and then some parameters. Is this the same as PERFORM Z_TEST_1(Para1, para2,etc..).
For example, CALL_METHOD_CHECK_ALL 'DOC_TYPE' DOC_TYPE ZTABLE1-fielda_A.
Where can find source code for these CALL_METHOD statements?
What are the CALL_METHOD statements?The CALL METHOD is a key word for calling the OO methods.
We have global classes (created using SE24 transaction) and local classes (using SE38), which contains the collection of methods and attributes.
The method is a block of code which will have the business logic (like Subroutine as you mentioned) and the attributes are the parameters wherein you will inport/ export the data.
The above said methods in the class will be called using the keyword "CALL METHOD".
Before calling the method, we need to create an Object for the class. (If it is a static class we can call the method using the class name itself)
TYPES: obj1 TYPE REF TO zcl_sample.
CREATE OBJECT obj1
EXPPORTING
IMPORTING
EXCEPTIONS.
(while creating the method, the special method constructor will be called)
After the creation of the method, we need to call the method like the below,
CALL METHOD obj1->add
EXPORTING
IMPORTING
The above method is call as "Instance Method"
Static method does not require any method.
CALL METHOD zcl_sample=>add
Hope you understand.
Rgds,
Benu -
How to call a private method in a JFrame
I have a Frame which has some properties like its size, bgcolor plus other parameters, as instance variables. There is a button on the Frame with the caption : "set properties". When one clicks on that button, a new frame should appear via which a user can change the values of the parameters of the main Frame (i.e size, bgcolor,..etc). The user would input the new values in the textfields or radio buttons that are on the new frame, and then click a submit button, which has to exist on the same NFrame. How can I do that so that when the submit button is pressed, the parameters values are updated and so is the display view ?
I made it this way : I created 2 classes, the main frame and the new Frame. I made the new Frame an instance variable of the main Frame. When the user clicks the " set properties" button on the main Frame, the new Frame is shown. The user enters new values for some of the parameters and clicks submit. The parameters in the new Frame are updated. UP TO HERE EVERYTHING WENT JUST FINE. Now, there is a private method in the main frame that changes the color, size, ...etc of the main frame according to the values stored in the instance variables color, size,...etc. THE QUESTION IS: How can the new Frame display the changes after the values have been updated ? That is, how can it call the "private" method in the main class?? Should the new class be a child class of the main class to be able to access it's private methods ??import java.awt.*;
import java.awt.event.*;
import java.util.Random;
import javax.swing.*;
public class CallingHome
SkinMod skinMod;
JPanel panel;
public CallingHome()
// send reference so SkinMod can call methods in this class
skinMod = new SkinMod(this);
JButton change = new JButton("change properties");
change.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
skinMod.showDialog();
JPanel north = new JPanel();
north.add(change);
panel = new JPanel();
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(north, "North");
f.getContentPane().add(panel);
f.setSize(300,100);
f.setLocation(200,200);
f.setVisible(true);
public void setBackground(Color color)
panel.setBackground(color);
panel.repaint();
public static void main(String[] args)
new CallingHome();
class SkinMod
CallingHome callHome;
Random seed;
JDialog dialog;
public SkinMod(CallingHome ch)
callHome = ch;
seed = new Random();
createDialog();
public void showDialog()
if(!dialog.isShowing())
dialog.setVisible(true);
private void createDialog()
JButton change = new JButton("change background");
change.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
callHome.setBackground(getColor());
dialog.dispose();
JPanel p = new JPanel();
p.add(change);
dialog = new JDialog();
dialog.getContentPane().add(p);
dialog.setSize(200,100);
dialog.setLocation(525,200);
private Color getColor()
return new Color(seed.nextInt(0xffffff));
} -
Calling a method on a jFrame from a jPanel that created by the jFrame
Hi all
I can not for the life of me work out how to do this.
Calling a method on a jFrame from a jPanel that created by the jFrame.
I have used this code to set a handle for one jPanel to another.
i.e I can create new jpanel and pass in handles from one to another but not back to the jFrame.
// this is sudo code
private Panel_Top topPanel;
private Menu_Panel menuPanel;
private DataPanel dataPanel;
//create new
topPanel = new Panel_Top();
menuPanel = new Menu_Panel();
dataPanel = new DataPanel();
// add handles from one to another
menuPanel.setDataPanel(dataPanel);
topPanel.setDataPanel(dataPanel);
topPanel.setMenu_Panel(menuPanel);
dataPanel.setMenu_Panel(menuPanel);
// in each class I use this to set
public void setDataPanel(DataPanel dataPanel) {
this.dataPanel = dataPanel;
}But I can not seam to get a handle back to the jFrame that created it.
Please help
as you can see I am trying but no luck so far
Thanksclass Life extends JPanel{
pulic Life( JFrame owner )
owner.doSomething(); // pass the JFrame to the constructor and feel free to use it
}[code[ -
Lag Time in Calling Methods?
I ran the two code examples below and got the same elapsed time for both: 10 ms. I was wondering whether calling a method causes lag: for instance, if you had to add four components to a frame's content pane, would calling getContentPane() four times be less efficient than setting up a reference to the content pane container and adding the four components to the container that that is returned?
The reason why I think that there would be a lag time, however infinitessimal, is because calling a method pushes an EIP onto the stack and returning from a method pops the EIP from the stack. It only makes sense that skipping this step would result in faster execution (once again, however infinitessimally faster that would be).
Here is the code for the two programs I used to test this out. The examples go back to my example above -- I am setting up a reference to the content pane in one example and continually returning it in the other. As I said, both returned the same elapsed time: 10 ms. I'm not sure whether my method of timing the programs was inaccurate or whether there really is no lag time in calling a method. What is the verdict?
1)
package cntrl.testing;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.Container;
public class Test1 extends JFrame
public Test1()
long i = new Date().getTime();
this.setSize(500, 500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = this.getContentPane();
c.add(new JButton());
c.add(new JButton());
c.add(new JButton());
c.add(new JButton());
long f = new Date().getTime();
long te = f - i;
System.out.println("Time elapsed: " + te + " ms");
public static void main(String[] args)
new Test1();
}2)
package cntrl.testing;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JButton;
public class Test2 extends JFrame
public Test2()
long i = new Date().getTime();
this.setSize(500, 500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().add(new JButton());
this.getContentPane().add(new JButton());
this.getContentPane().add(new JButton());
this.getContentPane().add(new JButton());
long f = new Date().getTime();
long te = f - i;
System.out.println("Time elapsed: " + te + " ms");
public static void main(String[] args)
new Test2();
}You're probably using some operating system where the smallest time interval you can measure is 10 milliseconds.
I would suggest that pushing something onto the stack would take an interval measured in nanoseconds. You have, let's say, a 1 gigahertz machine? That means it performs one billion operations per second, give or take. That's one per nanosecond.
There are a million nanoseconds in a millisecond. You're going to have to run a LOT of code to take a measurable amount of time. -
Syntax for how to call method of one comp in other comp wd java.
Let us assume,
there is method1 in view1 comp1.
tell me syntax for calling method 1 in view2 comp2
thanks in advance.
Edited by: madhu1011 on Nov 9, 2011 11:31 AMHi Madhu,
This is the situation:
comp1-> method 1 , view1
comp2-> view2
You need to access method1 in view2 of comp2.
For that, do the following steps:
1.) First create a method (for eg: method1) in comp1 (under implementation of view1).
eg: public void method1(){
<......some logic...>
2.)Save the meta data.
3.) In comp2, you will find an option called used components. In that right click and add the component comp2. (Carefully select comp1 itslef).
4.)Save the meta data.
5.) Then go to view2 of comp2 and take implementaion part and right the following logic in wddoinit() (or any other standard or custom method).
wdThis.wdGetComp2Interface().getMethod("method1");
By this way, we can access the method1 of comp1 in comp2.
Regards,
Jithin -
Trouble Getting Any Display of JFrame Components
Hello all! I appreciate being able to post questions on this forum, and am grateful for anyone's help with this.
I have written a program that displays a GUI and (will) read a random word from a file for use in a Hangman-like game.
The trouble is, today I have no display (yesterday I had display just fine!). When I run the program, it opens just an empty Container with nothing inside.
Am I crazy, but does my code create valid content for a display?
Also, I use NetBeans 6.1.
Would anyone know why one day I would get good display and the next nothing?
Any advice or suggestions for my code are greatly appreciated! Thanks!
package secretphraseusingfile;
import java.io.*; //program uses IOStreams
import java.awt.*; //program uses Font, Colors
import java.awt.geom.*; //program uses shapes
import java.awt.event.*;//program uses ActionListeners
import javax.swing.*; //program uses JOptionPane, JFrame
//Class SecretPhraseUsingFile
class DrawPanel extends JPanel
int type = 1;
public DrawPanel(int type)
this.type = type;
@Override
protected void paintComponent(Graphics gr)
super.paintComponent(gr);
Color gallowColor = new Color(100, 100, 15);
Graphics2D gr2D = (Graphics2D)gr;
gr2D.setColor(gallowColor);
gr2D.draw(new Rectangle2D.Float(100F, 50F, 400F, 333F));
gr2D.fillRect(210, 60, 20, 300);
gr2D.fillRect(230, 60, 120, 20);
gr2D.fillRect(320, 80, 4, 50);
}//end paintComponent
}//end DrawPanel
public class SecretPhraseUsingFile extends JFrame
implements ActionListener
DataInputStream istream;
//declaration of program-wide variables
String letter = "";
String filePath = "C:\\Users\\Ben\\Desktop\\Lesson 13\\Hangman";
String fileName = "secretList.dat";
File wordFile = new File(filePath, fileName);
//declaration of JFrame components
//layouts
GridLayout masterGrid = new GridLayout(2, 1);
GridLayout topGrid = new GridLayout(1, 2);
GridLayout bottomGrid = new GridLayout(3, 1);
GridLayout innerButtonsGrid = new GridLayout(6, 5, 15, 2);
FlowLayout innerFlow = new FlowLayout();
//panels
JPanel masterP = new JPanel(masterGrid);
JPanel topP = new JPanel(topGrid);
DrawPanel drawingP = new DrawPanel(1);
JPanel usedP = new JPanel(innerFlow);
JPanel bottomP = new JPanel(bottomGrid);
JPanel wordP = new JPanel(innerFlow);
JPanel buttonP = new JPanel(innerButtonsGrid);
JPanel captionP = new JPanel(innerFlow);
Container con = new Container();
//fonts
Font buttonsFont = new Font("Arial Black", Font.BOLD, 16);
Font usedFont = new Font("Courier New", Font.BOLD, 54);
Font usedTitleFont = new Font("Courier New", Font.BOLD, 34);
Font wordFont = new Font("Arial Black", Font.BOLD, 84);
Font captionFont = new Font("Helvetica", Font.BOLD, 30);
Font captionExtremeFont = new Font("Helvetica", Font.BOLD, 36);
//colors
Color backgroundColor = new Color(100, 180, 230);
Color buttonColor = new Color(70, 170, 150);
Color gallowColor = new Color(100, 100, 15);
//labels
JLabel caption = new JLabel("Uh oh!");
JLabel usedL[] = new JLabel[26];
JLabel lblLettersUsed = new JLabel("Letters You've Used So Far: ");
JLabel wordLabel = new JLabel("_ _ _ _ _ _ _ _ _");
//buttons
JButton abc[] = new JButton[26];
JButton exitButton = new JButton("EXIT");
//JFrame constructor//////////////////////////////////////
public SecretPhraseUsingFile()
super("Hangman Game Using File");
//create alphabet buttons
for(int i = 0; i < 26; i++)
letter = Character.toString((char)(i + 65));
abc[i] = new JButton(letter);
abc.setFont(buttonsFont);
abc[i].setBackground(buttonColor);
abc[i].setBorder(BorderFactory.createLineBorder(Color.BLACK));
//create used letter array for display of used letters
for(int i = 0; i < 26; i++)
letter = Character.toString((char)(i + 65));
usedL[i] = new JLabel(" " + letter + " ");
//keeps used letters invisible until chosen in game
usedL[i].setVisible(false);
usedL[i].setFont(usedFont);
usedL[i].setForeground(Color.RED);
drawingP.setBackground(backgroundColor);
usedP.setBackground(backgroundColor);
wordP.setBackground(backgroundColor);
buttonP.setBackground(backgroundColor);
captionP.setBackground(backgroundColor);
caption.setFont(captionFont);
con.add(masterP);
masterP.add(topP);
masterP.add(bottomP);
topP.add(drawingP);
topP.add(usedP);
bottomP.add(wordP);
bottomP.add(buttonP);
bottomP.add(captionP);
captionP.add(caption);
wordP.add(wordLabel);
wordLabel.setFont(wordFont);
for(int i = 0; i < 26; i++)
buttonP.add(abc[i]);
abc[i].addActionListener(this);
usedP.add(lblLettersUsed);
lblLettersUsed.setFont(usedTitleFont);
for(int i = 0; i < 26; i++)
usedP.add(usedL[i]);
buttonP.add(exitButton);
exitButton.addActionListener(this);
//create file opening for read from file
try
istream = new DataInputStream(new FileInputStream(wordFile));
catch(IOException ioe)
System.err.println("File not opened. " + "Cause: " + ioe.getMessage());
}//end of constructor
//main method runs java program
public static void main(String[] args) {
//declaration of constants
int DELTA_X = 0, DELTA_Y = 0;
int FRAME_WIDTH = 1280, FRAME_HEIGHT = 770;
//declaration of JFrame
SecretPhraseUsingFile display = new SecretPhraseUsingFile();
display.setBounds(DELTA_X, DELTA_Y, FRAME_WIDTH, FRAME_HEIGHT);
display.setVisible(true);
display.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}//end of method main
public void actionPerformed(ActionEvent e)
Object source = e.getSource();
if(source == exitButton)
exitProgram();
else if(source == abc[0]) //'A'
System.out.println("AAAAAAAAAA");
else if(source == abc[1]) //'B'
System.out.println("BBBBBBBBBB");
else if(source == abc[2]) //'C'
System.out.println("CCCCCCCCCC");
else if(source == abc[3]) //'D'
System.out.println("DDDDDDDDDD");
else if(source == abc[4]) //'E'
System.out.println("EEEEEEEEEE");
else if(source == abc[5]) //'F'
System.out.println("FFFFFFFFFF");
else if(source == abc[6]) //'G'
System.out.println("GGGGGGGGGG");
else if(source == abc[7]) //'H'
System.out.println("HHHHHHHHHH");
else if(source == abc[8]) //'I'
System.out.println("IIIIIIIIII");
else if(source == abc[9]) //'J'
System.out.println("JJJJJJJJJJ");
else if(source == abc[10])//'K'
System.out.println("KKKKKKKKKK");
else if(source == abc[11])//'L'
System.out.println("LLLLLLLLLL");
else if(source == abc[12])//'M'
System.out.println("MMMMMMMMMM");
else if(source == abc[13])//'N'
System.out.println("NNNNNNNNNN");
else if(source == abc[14])//'O'
System.out.println("OOOOOOOOOO");
else if(source == abc[15])//'P'
System.out.println("PPPPPPPPPP");
else if(source == abc[16])//'Q'
System.out.println("QQQQQQQQQQ");
else if(source == abc[17])//'R'
System.out.println("RRRRRRRRRR");
else if(source == abc[18])//'S'
System.out.println("SSSSSSSSSS");
else if(source == abc[19])//'T'
System.out.println("TTTTTTTTTT");
else if(source == abc[20])//'U'
System.out.println("UUUUUUUUUU");
else if(source == abc[21])//'V'
System.out.println("VVVVVVVVVV");
else if(source == abc[22])//'W'
System.out.println("WWWWWWWWWW");
else if(source == abc[23])//'X'
System.out.println("XXXXXXXXXX");
else if(source == abc[24])//'Y'
System.out.println("YYYYYYYYYY");
else if(source == abc[25])//'Z'
System.out.println("ZZZZZZZZZZ");
}//end of actionPerformed()
@Override
public void paint(Graphics brush)
super.paint(brush);
//Graphics2D g2D = (Graphics2D)brush;
}//end paint()
public void exitProgram()
int answer = 1;
answer = JOptionPane.showConfirmDialog(null,
"Do you want to quit?");
if(answer == 0)
System.exit(0);
}//end exitProgram()
}//end of class SecretPhraseUsingFileThanks JSG. Yeah, I definitely have too much in my constructor for sure. I just do that because I am uneasy about creating methods that I don't know how to use well. I am just now getting the hang of using try catch statements (they are very confusing!) and also knowing how to use FileStreams correctly (that took me forever to learn, and I still need work on it). I know that I need serious study of program architecture, how to design a program well. As for now, I'm content with smalll programs that at least work (albeit clunky).
I will try to implement your suggestions about the methods and about using super, I'm sure that I could do better with them. Thanks! -
Error calling methods CL_GUI_FRONTEND_SERVICES
Hi all,
I have a requirement in BAPI (integrating solman to portal) to download file from app. server to local directory. I used the below FM to get temp directory of presntation server.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GET_TEMP_DIRECTORY
CHANGING
TEMP_DIR = LV_TEMP_DIR
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
others = 4.
CALL METHOD cl_gui_cfw=>flush.
It works fine in R3, but when i called it from portal it shows Access not possible using 'NULL' object reference with a short dump .
st22 shows
Error in ABAP application program.
The current ABAP program "CL_GUI_FRONTEND_SERVICES======CP" had to be
terminated because one of the
statements could not be executed.
This is probably due to an error in the ABAP program.
An exception occurred. This exception is dealt with in more detail belo
. The exception, which is assigned to the class 'CX_SY_REF_IS_INITIAL',
neither
caught nor passed along using a RAISING clause, in the procedure
"GET_TEMP_DIRECTORY" "(METHOD)"
Since the caller of the procedure could not have expected this exceptio
to occur, the running program was terminated.
The reason for the exception is:
Attempt to access a component using 'NULL' object reference (points
to nothing).
An object reference must point to an object (an instance of a class)
before you can use it to access components (variable:
"CL_GUI_FRONTEND_SERVICES=>HANDLE").
Either the reference has not yet been set, or it has been reset to
'NULL' by a CLEAR statement.
When i put external break point and the dump comes during execution of CALL METHOD cl_gui_cfw=>flush.
Is it not possible to use CL_GUI_FRONTEND_SERVICES in RFC ??.
thanks and regards
JijoHi,
the dump is because you cannot use that function from a BSP application, which runs in internet or intranet. The procedure in this case is different:
DATA: flights TYPE flighttab,
flight LIKE LINE OF flights,
appl TYPE string,
filetype TYPE string,
output TYPE string,
output2 TYPE xstring,
response TYPE REF TO if_http_response,
l_len TYPE i,
seatsmax TYPE string,
seatsocc TYPE string.
appl = 'application/msexcel'.
filetype = 'attachment;filename=mi archivo.xls'.
SELECT * FROM sflight
INTO TABLE flights
UP TO 20 ROWS.
LOOP AT flights INTO flight.
seatsmax = flight-seatsmax. CONDENSE seatsmax.
seatsocc = flight-seatsocc. CONDENSE seatsocc.
CONCATENATE output
flight-carrid cl_abap_char_utilities=>horizontal_tab
flight-connid cl_abap_char_utilities=>horizontal_tab
flight-fldate cl_abap_char_utilities=>horizontal_tab
flight-planetype cl_abap_char_utilities=>horizontal_tab
seatsmax cl_abap_char_utilities=>horizontal_tab
seatsocc cl_abap_char_utilities=>horizontal_tab
cl_abap_char_utilities=>cr_lf
INTO output.
ENDLOOP.
response = runtime->server->response.
response->delete_header_field( name = if_http_header_fields=>cache_control ).
response->delete_header_field( name = if_http_header_fields=>expires ).
response->delete_header_field( name = if_http_header_fields=>pragma ).
response->set_header_field( name = if_http_header_fields=>content_type
value = appl ).
response->set_header_field( name = 'content-disposition'
value = filetype ).
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = output
mimetype = 'text/unicode; charset=utf-16le'
IMPORTING
buffer = output2.
CONCATENATE cl_abap_char_utilities=>byte_order_mark_little
output2 INTO output2 IN BYTE MODE.
l_len = XSTRLEN( output2 ).
response->set_data( data = output2
length = l_len ).
navigation->response_complete( ).
This is the code for downloading an Excel file. -
Dear experts,
I'm using CALL METHOD ob_grid1->set_table_for_first_display, during the first run the display is ok.
When I back to screen 0 and enter different values and re-run, the values of internal table has been changed.
But the second run still display the values I have during the first run. What could be the reason for this and how to solve this? Thanks.
IF ob_custom1 IS INITIAL.
CREATE OBJECT ob_custom1
EXPORTING
container_name = 'ALV_CONTAINER'.
ENDIF.
IF ob_split1 IS INITIAL.
CREATE OBJECT ob_split1
EXPORTING
parent = ob_custom1
orientation = cl_gui_easy_splitter_container=>orientation_vertical.
ENDIF.
IF ob_grid1 IS INITIAL.
CREATE OBJECT ob_grid1
EXPORTING
i_parent = ob_split1->top_left_container.
PERFORM build_fieldcatalog.
gs_layout1-info_fname = 'ROWCOLOR'.
gs_layout1-smalltitle = 'X'.
CALL METHOD ob_grid1->set_table_for_first_display
EXPORTING
i_structure_name = 'T_REPORT'
is_layout = gs_layout1
CHANGING
it_outtab = T_REPORT
it_fieldcatalog = alv_fcat_dock1.
ENDIF.
KathHi,
Please add the code after else statement.
IF ob_grid1 IS INITIAL.
CREATE OBJECT ob_grid1
EXPORTING
i_parent = ob_split1->top_left_container.
PERFORM build_fieldcatalog.
gs_layout1-info_fname = 'ROWCOLOR'.
gs_layout1-smalltitle = 'X'.
CALL METHOD ob_grid1->set_table_for_first_display
EXPORTING
i_structure_name = 'T_REPORT'
is_layout = gs_layout1
CHANGING
it_outtab = T_REPORT
it_fieldcatalog = alv_fcat_dock1.
ELSE. " Add
Call method refersh table for display. " Add
ENDIF. -
How to Call Methods of one component into another Component
Hi Experts,
I have one requirement...
I have 2 components A and B, i used A comp in B, i need to call Comp A methods in Component B, can anybody give me the syntax?? please...
Thanks and Regards,
Kissna.Hi Manas Thanks for your fast reply,
My question is, for example we have wd_comp_controller or wd_this objects to call methods of view from view and comp controller right.. like this we have any methods to call used component methods? if yes can u please give me the objects syntax?...
Thanks and regards,
Kissna. -
Error on Calling Methods Using an Object of a Class
I keep getting the error cannot resolve variable addStud . I can't figure out why. I've created objects of classes before this way, then called methods within that class like this and it worked fine. I can't discern any difference between the syntax of the program that worked successfully and this one. I commented the parts where the error is when I tried to send a variable to a method in the class Recieve of which addStud is an object of. If you can see something that I can't I'd appreciate it. I've checked the obvious things like making sure the class name and method name is spelled the same way in both my frame and the class file.
import java.awt.event.*;
import java.awt.*; /* Used by IntroTest3.java. */
import javax.swing.*;
public class RegFrame extends JInternalFrame
{ // Begin class RegFrame
static final int xOffset = 30, yOffset = 30;
private JLabel nameLabel, displayLabel;
private JTextField nameField;
private JTextArea displayText;
private JButton addButton;
private String name;
private int numStu;
public RegFrame() { // Begin RegFrame constructor
super(" Register a New Student ",
true, //resizable
true, //closable
true, //maximizable
true);//iconifiable
//...Create the GUI and put it in the window...
//...Then set the window size or call pack...
setSize(400,300); //Set the window's location.
setLocation(xOffset, yOffset);
Container content = getContentPane();
setBackground(Color.white);
content.setBackground(Color.white);
content.setLayout( new FlowLayout());
//* CREATE LABELS AND TEST ENTRY FIELDS FOR REGISTERING A NEW STUDENT *
* HERE IS WHERE OBJECT OF RECIEVE IS CREATED *
Recieve addStud = new Recieve();
nameLabel = new JLabel(" Enter student name: ");
nameField = new JTextField(20);
content.add ( nameLabel );
content.add ( nameField );
addButton = new JButton( "Add Student" );
content.add( addButton );
addButton.addActionListener(
new ActionListener()
{ // Open ActionListener
public void actionPerformed (ActionEvent e)
getInput();
} // Close ActionListener
} // End RegFrame Constructor
// get input
private void getInput()
numStu++;
name = nameField.getText();
JOptionPane.showMessageDialog( null, "NAME: " + name + "\n"
+ "Student number:"+ numStu );
addStud.addName( name ); /** <--- HERE IS ERROR **/
} // End class RegFrame;This is the class:
public class Recieve
{ // Begin class Recieve
private double stAssign[];
private double stLab[];
private double stProject[];
private double stQuiz[];
private double stTest[];
private String stNames[];
int snc;
public Recieve ()
stAssign = new double[10];
stLab = new double[10];
stProject = new double[10];
stQuiz = new double[10];
stTest = new double[10];
stNames = new String[10];
snc = 0; // Student Name Counter
public void addName (String stName)
stNames[snc] = stName;
snc++;
} // End class Recieve1- Add the following class variable declaration for RegFrame:
private Recieve addStud;2- Change in the RegFrame constructor:
addStud = new Recieve(); -
CALL METHOD g_editor- get_text_as_r3table
Hi everyone!!!,
I have some problems with CALL METHOD g_editor->get_text_as_r3table, I can't retrieve the text from my custom editor. Can anyone please help me with this issue?.
DATA: g_mytable(line_length) TYPE c OCCURS 0.
CALL METHOD g_editor->get_text_as_r3table
IMPORTING
table = g_mytable.
CALL METHOD cl_gui_cfw=>flush
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
add your handling
ENDIF.
Regards...Check this code...
data:
dockingleft type ref to cl_gui_docking_container,
text_editor type ref to cl_gui_textedit,
repid type syrepid.
data: itext type table of tline-tdline,
xtext type tline-tdline.
parameters: p_check.
at selection-screen output.
repid = sy-repid.
create object dockingleft
exporting repid = repid
dynnr = sy-dynnr
side = dockingleft->dock_at_left
extension = 1070.
create object text_editor
exporting
parent = dockingleft.
xtext = 'http:\\www.sap.com'.
append xtext to itext.
call method text_editor->set_text_as_r3table
exporting
table = itext
exceptions
others = 1.
start-of-selection.
call method text_editor->get_text_as_r3table
importing
table = itext
exceptions
others = 1.
loop at itext into xtext.
write:/ xtext.
endloop.
Kindly stolen from Rich Heilman -;)
Greetings,
Blag. -
Is it possible to call methods from another class from within an abstract c
Is it possible to call methods from another class from within an abstract class ?
I found an example in teh JDK 131 JFC that may help you. I t is using swing interface and JTable
If you can not use Swing, then you may want to do digging or try out with the idea presented here in example 3
Notice that one should refine the abstract table model and you may want to create a method for something like
public Object getValuesAtRow(int row) { return data[row;}
to give the desired row and leave the method for
getValuesAt alone for getting valued of particaular row and column.
So Once you got the seelcted row index, idxSelctd, from your table
you can get the row or set the row in your table model
public TableExample3() {
JFrame frame = new JFrame("Table");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}});
// Take the dummy data from SwingSet.
final String[] names = {"First Name", "Last Name", "Favorite Color",
"Favorite Number", "Vegetarian"};
final Object[][] data = {
{"Mark", "Andrews", "Red", new Integer(2), new Boolean(true)},
{"Tom", "Ball", "Blue", new Integer(99), new Boolean(false)},
{"Alan", "Chung", "Green", new Integer(838), new Boolean(false)},
{"Jeff", "Dinkins", "Turquois", new Integer(8), new Boolean(true)},
{"Amy", "Fowler", "Yellow", new Integer(3), new Boolean(false)},
{"Brian", "Gerhold", "Green", new Integer(0), new Boolean(false)},
{"James", "Gosling", "Pink", new Integer(21), new Boolean(false)},
{"David", "Karlton", "Red", new Integer(1), new Boolean(false)},
{"Dave", "Kloba", "Yellow", new Integer(14), new Boolean(false)},
{"Peter", "Korn", "Purple", new Integer(12), new Boolean(false)},
{"Phil", "Milne", "Purple", new Integer(3), new Boolean(false)},
{"Dave", "Moore", "Green", new Integer(88), new Boolean(false)},
{"Hans", "Muller", "Maroon", new Integer(5), new Boolean(false)},
{"Rick", "Levenson", "Blue", new Integer(2), new Boolean(false)},
{"Tim", "Prinzing", "Blue", new Integer(22), new Boolean(false)},
{"Chester", "Rose", "Black", new Integer(0), new Boolean(false)},
{"Ray", "Ryan", "Gray", new Integer(77), new Boolean(false)},
{"Georges", "Saab", "Red", new Integer(4), new Boolean(false)},
{"Willie", "Walker", "Phthalo Blue", new Integer(4), new Boolean(false)},
{"Kathy", "Walrath", "Blue", new Integer(8), new Boolean(false)},
{"Arnaud", "Weber", "Green", new Integer(44), new Boolean(false)}
// Create a model of the data.
TableModel dataModel = new AbstractTableModel() {
// These methods always need to be implemented.
public int getColumnCount() { return names.length; }
public int getRowCount() { return data.length;}
public Object getValueAt(int row, int col) {return data[row][col];}
// The default implementations of these methods in
// AbstractTableModel would work, but we can refine them.
public String getColumnName(int column) {return names[column];}
public Class getColumnClass(int col) {return getValueAt(0,col).getClass();}
public boolean isCellEditable(int row, int col) {return (col==4);}
public void setValueAt(Object aValue, int row, int column) {
data[row][column] = aValue;
};
Maybe you are looking for
-
Yoga 3 pro cant stream video on external display or laptop
Saw a previous post on this, didnt seem like it was fixed. Having real issues with hooking up to an external display, when the web browser (chrome) is extended to the external display, my internet lags hard...i cant even stream a vid on youtube. I'v
-
How to add a link to your message
Does anyone know how to add a link to a message?
-
How to create an installable package
Hi all we have developed some ABAP objects on R/3 4.6c.Is there a way by which i can convert my developments in to a installable package(copy it on a CD) much similar to the support packages supplied by SAP to its customers.Since the target system wi
-
CS4 Installation on OS X?
Will Master Collection CS4 (specifically the Acrobat Pro software) install OK on a new MacBook Air? Also, does my license allow me to install on two computers (both are mine).
-
I reported a line fault in October, which was subsequently fixed by an Engineer's visit. The fault was to the line outside the house, (before the master socket). Broadband fault VOL051-*************. I have since migrated to another supplier after t