call frame

call frame

View Answers

January 23, 2009 at 5:18 AM

Hi friend,


I am sending you a running code. I hope that, following code will help you. If you have any type problem then send me code and explain in detail.


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;

public class FrameDemo extends WindowAdapter implements ActionListener {
private Point lastLocation = null;
private int maxX = 500;
private int maxY = 500;

private static JButton defaultButton = null;

//constants for action commands
protected final static String NO_DECORATIONS = "no_dec";
protected final static String LF_DECORATIONS = "laf_dec";
protected final static String WS_DECORATIONS = "ws_dec";
protected final static String CREATE_WINDOW = "new_win";
protected final static String DEFAULT_ICON = "def_icon";
protected final static String FILE_ICON = "file_icon";
protected final static String PAINT_ICON = "paint_icon";

//true if the next frame created should have no window decorations
protected boolean noDecorations = false;

//true if the next frame created should have setIconImage called
protected boolean specifyIcon = false;

//true if the next frame created should have a custom painted icon
protected boolean createIcon = false;

//Perform some initialization.
public FrameDemo() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
maxX = screenSize.width - 50;
maxY = screenSize.height - 50;
}

//Create a new MyFrame object and show it.
public void showNewWindow() {
JFrame frame = new MyFrame();

if (noDecorations) {
frame.setUndecorated(true);
}

if (specifyIcon) {
if(createIcon) {
frame.setIconImage(createFDImage());
}
else {
frame.setIconImage(getFDImage());
}
}

frame.setSize(250,150);
frame.setVisible(true);
}

January 23, 2009 at 5:19 AM

// Create the window-creation controls that go in the main window.
protected JComponent createOptionControls() {
JLabel label1 = new JLabel("Decoration options for subsequently created frames:");
ButtonGroup bg1 = new ButtonGroup();
JLabel label2 = new JLabel("Icon options:");
ButtonGroup bg2 = new ButtonGroup();

//Create the buttons
JRadioButton rb1 = new JRadioButton();
rb1.setText("Look and feel decorated");
rb1.setActionCommand(LF_DECORATIONS);
rb1.addActionListener(this);
rb1.setSelected(true);
bg1.add(rb1);

JRadioButton rb2 = new JRadioButton();
rb2.setText("Window system decorated");
rb2.setActionCommand(WS_DECORATIONS);
rb2.addActionListener(this);
bg1.add(rb2);

JRadioButton rb3 = new JRadioButton();
rb3.setText("No decorations");
rb3.setActionCommand(NO_DECORATIONS);
rb3.addActionListener(this);
bg1.add(rb3);

JRadioButton rb4 = new JRadioButton();
rb4.setText("Default icon");
rb4.setActionCommand(DEFAULT_ICON);
rb4.addActionListener(this);
rb4.setSelected(true);
bg2.add(rb4);

JRadioButton rb5 = new JRadioButton();
rb5.setText("Icon from a JPEG file");
rb5.setActionCommand(FILE_ICON);
rb5.addActionListener(this);
bg2.add(rb5);

JRadioButton rb6 = new JRadioButton();
rb6.setText("Painted icon");
rb6.setActionCommand(PAINT_ICON);
rb6.addActionListener(this);
bg2.add(rb6);

//Add everything to a container.
Box box = Box.createVerticalBox();
box.add(label1);
box.add(Box.createVerticalStrut(5));
box.add(rb1);
box.add(rb2);
box.add(rb3);

box.add(Box.createVerticalStrut(15));
box.add(label2);
box.add(Box.createVerticalStrut(5));
box.add(rb4);
box.add(rb5);
box.add(rb6);

//Add some breathing room.
box.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
return box;
}

January 23, 2009 at 5:20 AM

//Create the button that goes in the main window.
protected JComponent createButtonPane() {
JButton button = new JButton("New window");
button.setActionCommand(CREATE_WINDOW);
button.addActionListener(this);
defaultButton = button; //Used later to make this the frame's default button.

//Center the button in a panel with some space around it.
JPanel pane = new JPanel();
pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
pane.add(button);

return pane;
}

//Handle action events from all the buttons.
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();

//Handle the New window button.
if(CREATE_WINDOW.equals(command)) {
showNewWindow();

//Handle the first group of radio buttons.
}
else if(NO_DECORATIONS.equals(command)) {
noDecorations = true;
JFrame.setDefaultLookAndFeelDecorated(false);
}
else if (WS_DECORATIONS.equals(command)) {
noDecorations = false;
JFrame.setDefaultLookAndFeelDecorated(false);
}
else if(LF_DECORATIONS.equals(command)) {
noDecorations = false;
JFrame.setDefaultLookAndFeelDecorated(true);

//Handle the second group of radio buttons.
}
else if (DEFAULT_ICON.equals(command)) {
specifyIcon = false;
}
else if (FILE_ICON.equals(command)) {
specifyIcon = true;
createIcon = false;
}
else if (PAINT_ICON.equals(command)) {
specifyIcon = true;
createIcon = true;
}
}

//Creates an icon-worthy Image from scratch.
protected static Image createFDImage() {
//Create image.
BufferedImage bi = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);

//Draw into it.
Graphics g = bi.getGraphics();
g.setColor(Color.BLACK);
g.fillRect(0, 0, 15, 15);
g.setColor(Color.RED);
g.fillOval(5, 3, 6, 6);

//Clean up.
g.dispose();

//Return it.
return bi;
}

January 23, 2009 at 5:22 AM

protected static Image getFDImage() {
java.net.URL imgURL = FrameDemo.class.getResource("images/FD.jpg");
if (imgURL != null) {
return new ImageIcon(imgURL).getImage();
}
else {
return null;
}
}

private static void createAndShowGUI() {
//Use the Java look and feel.
try {
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName());
}
catch(Exception e){
System.out.println("error" + e.getMessage());
}

//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);

//Instantiate the controlling class.
JFrame frame = new JFrame("FrameDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Create and set up the content pane.
FrameDemo demo = new FrameDemo();

//Add components to it.
Container contentPane = frame.getContentPane();
contentPane.add(demo.createOptionControls(),
BorderLayout.CENTER);
contentPane.add(demo.createButtonPane(),
BorderLayout.PAGE_END);
frame.getRootPane().setDefaultButton(defaultButton);

//Display the window.
frame.setSize(400,300);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}

public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}

January 23, 2009 at 5:57 AM

public class MyFrame extends JFrame implements ActionListener {

//Create a frame with a button.
public MyFrame() {
super("New Open window");
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
JButton button = new JButton("Close window");
button.addActionListener(this);

//Place the button near the bottom of the window.
Container contentPane = getContentPane();
contentPane.setLayout(new BoxLayout(contentPane,
BoxLayout.PAGE_AXIS));
contentPane.add(Box.createVerticalGlue());
contentPane.add(button);
button.setAlignmentX(Component.CENTER_ALIGNMENT);
contentPane.add(Box.createVerticalStrut(5));
}

public void actionPerformed(ActionEvent e) {
setVisible(false);
dispose();
}
}
}


--------------------------------------

visit for more information:

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

Thanks

Amardeep









Related Tutorials/Questions & Answers:
call frame - Java Beginners
call frame   dear java, I want to ask something about call frame to another frame and back to first frame. I have FrameA and FrameB. In frameA... String PAINT_ICON = "paint_icon"; //true if the next frame created should
call frame again - Java Beginners
call frame again  d, thank's for your answer, but i can't combine... can run ,first i have one frameA in this frame have one jTextfield1,one jbutton1,second i have FrameB in this frame have one Jtextfield1 and jbutton1. I can
Advertisements
how to call a frame having threading concept
how to call a frame having threading concept   i hav a frame having buttton on it .on click event of the button ,i want to call another frame which... of that frame ,frame is displaying but no other content. that frame contains
how to call a frame having threading concept
how to call a frame having threading concept   i hav a frame having buttton on it .on click event of the button ,i want to call another frame which... of that frame ,frame is displaying but no other content. that frame contains
FRAME
FRAME  WHILE I'M RUNNINGFILE OF A GUI PROGRAMME(JDBC CONNECTION) INSTEAD OF OUTPUT FRAME ONLY TWO BLANK FRAMES ARE GETTING DISPLAYD... CAN ANYONE HELP ME TO SOLVE DS PROBLEM
FRAME
FRAME  WHILE I'M RUNNINGFILE OF A GUI PROGRAMME(JDBC CONNECTION) INSTEAD OF OUTPUT FRAME ONLY TWO BLANK FRAMES ARE GETTING DISPLAYD... CAN ANYONE HELP ME TO SOLVE DS PROBLEM
frame
frame  how to creat a frame in java   Hi Friend, Try the following code:ADS_TO_REPLACE_1 import java.awt.*; import javax.swing.*; import java.awt.event.*; class RetrieveDataFromTextFields{ public static void
frame update another frame.
frame update another frame.   How do I make a link or form in one frame update another frame
one frame update another frame
one frame update another frame  How do I make a link or form in one frame update another frame
Frame query
Frame query  Hi, I am working on Images in java. I have two JFrame displaying same image. We shall call it outerFrame and innerFrame.In innerFrame i am rotating the image.After all the rotations i need to display this image
panel and frame
panel and frame  What is the difference between panel and frame
Java Frame
Java Frame  What is the difference between a Window and a Frame
billing frame
billing frame  how to generate billing frame using swing which contain sr. no, name of product, quantity, price & total
Image on frame
Image on frame   Hi, This is my code. In this I am unable to load... java.awt.event.*; public class AwtImg extends Frame { Image img; public...(); } AwtImg() { super("Image Frame"); MediaTracker mt=new
frame generation
frame generation  Hi I wnat to genarate one frame with two tabs working ,production..and I want two radiobuttons sector ,others in the frames..based on the tab selection I want to clikc the radio button..when i ckick the radio
Frame
frame
how to create frame in swings
how to create frame in swings  how to create frame in swings
collection frame work
collection frame work  explain all the concept in collection frame work
link to other frame - Applet
link to other frame  how a button to open to another frame? and the frame can keyin the data and it can show at the previous frame
collection frame work
collection frame work  explain the hierarchy of one dimensional collection frame work classes
collection frame work
collection frame work  could you please tell me detail the concept of collection frame work
call a constructor
call a constructor  How do you call a constructor for a parent class
call ireports
call ireports  how to call jrxml file in jsp or servlets pls give one example any one? please send one example any one
Iphone call
Iphone call  Do you have other method to make a call on Iphone,without openUrl
making call
making call  Hi, Is it possible to make a call from application... this the code for call to a number NSString *phoneStr = [[NSString alloc... for call to a number ADS_TO_REPLACE_2 NSString *phoneStr = [[NSString alloc
conference call
conference call  hi am a java beginner I want to develop a simple conference call system over a LAN can u please enlighten me on the basics that I have to do and kno first
conference call
conference call  hi am a java beginner I want to develop a simple conference call system over a LAN can u please enlighten me on the basics that I have to do and kno first
conference call
conference call  hi am a java beginner I want to develop a simple conference call system over a LAN can u please enlighten me on the basics that I have to do and kno first
conference call
conference call  hi am a java beginner I want to develop a simple conference call system over a LAN can u please enlighten me on the basics that I have to do and kno first
conference call
conference call  hi am a java beginner I want to develop a simple conference call system over a LAN can u please enlighten me on the basics that I have to do and kno first
conference call
conference call  hi am a java beginner I want to develop a simple conference call system over a LAN can u please enlighten me on the basics that I have to do and kno first
conference call
conference call  hi am a java beginner I want to develop a simple conference call system over a LAN can u please enlighten me on the basics that I have to do and kno first
ModuleNotFoundError: No module named 'frame'
ModuleNotFoundError: No module named 'frame'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'frame' How to remove the ModuleNotFoundError: No module named 'frame'
Creating a Frame
; Setting the Icon for a Frame    Showing a Dialog Box  ... an Icon to a JButton Component    Making a Frame Non-Resizable    Removing the Title Bar of a Frame   
single frame coding in java
single frame coding in java  sir, i am a beginner in java.i want to do a desktop application in java in which a single frame satisfies all needs.but i want changes in that frame only.how can i solve this?i think multiple frames
Cross frame menus - Ajax
Cross frame menus  Respected Sir/Madam, I am Ragavendran.R.. I need to implement DHTML Cross frame menus..i.e There must be a page with 2 frames(top and bottom).. The main menus must be in the top frame and when I
spring MVC frame work - Spring
spring MVC frame work  Example of spring MVC frame work
another frame by using awt or swings
another frame by using awt or swings  how to connect one frame to another frame by using awt or swings
Frame with JDBC - JDBC
Frame with JDBC  What is the Frame in JDBC?  Hello,What is the structure of table and in which format you wan't to display the data.Last time also you posted the same question.Answer me the above question and I
Dialog Frame focus - Framework
Dialog Frame focus  Is it possible somehow to focus/activate/select... visit the parent frame also. But on some event(like a button), I want my dialog frame to be focussed/active.(Here i dont want to reopen it. As it is already opened
jumping frame jFrame to jInternalframe
jumping frame jFrame to jInternalframe  Afternoon sir, I want to ask something code like jumping frame. example this i have form Login , Menu...) , and in employee(jinternal Frame) have nik(jTexkfield1), name(jtextfield2
swing frame problem
swing frame problem  Hi All, I m creating a swing/awt based window... a frame which have few buttons and Text Box to get some data from user at this time when I will click on submit button then next frame should be open with in same
hibernat frame work
hibernat frame work  what is the deployment structure for 'hibernete.cfg.xml','contact.hbm.xml','Contact.java','FirstExample.java' programs into eclipse ide   Have a look at the following link: Hibernate Tutorial
Frame with JDBC - JDBC
Frame with JDBC   i am using frame having two textfield so how i retrieve the data from the ms-access there is two columns name and salary   Hi,Do you want to display the data on JSP Page?If yes then following tutorial
Frame works - Framework
Frame works  I need tutorials on JAVA Plugin Frameworks and hibernate and springs ? I new to these Technologies so i need with Examples to understand Using above technologies i need to do project. so ASAP pls
VoIP Call
VoIP Call VoIP Call quality Network testing and monitoring vendors are betting you will as they peddle new call quality management applications..., and businesses embracing VoIP can't afford to make assumptions about call quality
Call Procedure
Call Procedure      ... illustrate an example from 'Call Procedure'. In this Tutorial we create... ; Call Procedure The call stu(10) return you the records from
zend2 frame work
zend2 frame work  Hi can you please detail about Zend framework 2 latest folder structure and related things in details . I already seen zend website am confused with two old and new folder structures which one has to use
How to make frame of the picture, make frame of the picture, frame of the picture
How to make frame of the picture       This is about a frame example that has been made by some steps, I have mention here all the steps to make this effect. Take picture: First

Ads