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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


hendra
call frame
5 Answer(s)      5 years and 10 months ago
Posted in : Java Beginners



Advertisement
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: import java.awt.*; import javax.swing.*; import java.awt.event.*; class RetrieveDataFromTextFields{ public static void main(String[] args
frame update another frame.
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
one frame update another frame
one frame update another frame  How do I make a link or form in one frame update another frame
Java Frame
Java Frame  What is the difference between a Window and a Frame
panel and frame
panel and frame  What is the difference between panel and frame
call a constructor
call a constructor  How do you call a constructor for a parent class
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
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
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
making call
making call  Hi, Is it possible to make a call from application with out quitting application in iOS 4?   hello, this the code for call...]; [phoneStr release];   hello, this the code for call to a number
collection frame work
collection frame work  explain all the concept in collection frame work
how to create frame in swings
how to create frame in swings  how to create frame in swings
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   
 

 

 

DMCA.com