Problem in passing color as a parameter


, below code is for bounce multiple balls, my code is working correctly, but when i m trying to add Color also as a parameter, it not changing the color of the balls, code is:

Point.java

import java.applet.*; import java.awt.Color; import java.awt.Graphics; import java.awt.Image; public class Point extends Applet implements Runnable{ private Image i; private Graphics doubleG; Cfish f,f1,f2; public void init() { setSize(800,600); } public void start() { f = new Cfish(); f1 = new Cfish(250,250); f2 = new Cfish(350,350); Thread thread = new Thread(this);//if this confuses run method can also be done here... thread.start(); } public void run() { while(true) { f.update(this); f1.update(this); f2.update(this); repaint(); try { Thread.sleep(17); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void update(Graphics g) { if(i == null) { i = createImage(this.getSize().width, this.getSize().height); doubleG = i.getGraphics(); } doubleG.setColor(getBackground()); doubleG.fillRect(0, 0,this.getSize().width, this.getSize().height); doubleG.setColor(getForeground()); paint(doubleG); g.drawImage(i, 0, 0, this); } public void paint(Graphics g) { f.display(g); f1.display(g); f2.display(g); } }
Posted On: Wednesday 3rd of October 2012 12:19:46 AM Total Views:  71
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




problem in layout a form.

hello i have created a form layout using grid bag layout.. with four columns and few rows. but i need to add three combo boxes in second column (for date month and year), but they are overlapping to each other. here is my code.. import javax.swing.*; import javax.swing.border.MatteBorder; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class CustomerLayout extends JPanel { JPanel panel; JLabel lblName, lblGeneralRegistrationNumber, lblAddress, lblReligion, lblNationality, lblDob, lblBirthPlace, lblLastSchool, lblcategory, lblAdmissionDate, lblAdmittedClass, lblProgress, lblConduct, lblLeavingDate,lblLeavingStudies,lblLeavingCollegeReason,lblFeeDue, lblReceiptDate; JTextField txtGeneralRegistrationNumber, txtName, txtAddress,txtReligion, txtNationality, txtBirthPlace, txtLastSchool, txtcategory, txtAdmittedClass, txtProgress, txtConduct,txtLeavingStudies,txtLeavingCollegeReason, txtFeeDue; Integer date[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31}; Integer year[] = {1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999, 2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011}; String month[] = {"January", "Feburary", "March", "April", "May", "June","July","August","September","October", "November","December"}; JButton btnRegister; GridBagLayout gbLayout; GridBagConstraints gbc; public CustomerLayout() { gbLayout = new GridBagLayout(); gbc = new GridBagConstraints(); panel = new JPanel(); panel.setLayout(gbLayout); lblGeneralRegistrationNumber = new JLabel("General Register Number"); lblName = new JLabel("Name"); lblAddress = new JLabel("Address"); lblReligion = new JLabel("Religion and Caste"); lblNationality = new JLabel("Nationality"); lblBirthPlace = new JLabel("Place of Birth"); lblDob = new JLabel("Date of Birth(According Era)"); lblLastSchool = new JLabel("Last School/College Attended"); lblcategory = new JLabel("Category"); lblAdmissionDate = new JLabel("Date of Addmission"); lblAdmittedClass = new JLabel("Class in which Admitted"); lblProgress = new JLabel("Progress"); lblConduct = new JLabel("Conduct"); lblLeavingDate = new JLabel("Date of Leaving College"); lblLeavingStudies = new JLabel("Class in which at the time leaving"); lblLeavingCollegeReason = new JLabel("Reason of leaving college institue"); lblFeeDue = new JLabel("Fee Due"); lblReceiptDate = new JLabel("Date of Receipt of Fee Dues"); JComboBox dateCombo = new JComboBox(date); JComboBox monthCombo = new JComboBox(month); JComboBox yearCombo = new JComboBox(year); dateCombo.setPreferredSize(new Dimension(20,20)); txtGeneralRegistrationNumber = new JTextField(14); txtName = new JTextField(14); txtAddress = new JTextField(14); txtReligion = new JTextField(14); txtNationality = new JTextField(14); txtBirthPlace = new JTextField(14); //txtDob = new JTextField(); txtLastSchool = new JTextField(14); txtcategory = new JTextField(14); //txtAdmissionDate = new JTextField(); txtAdmittedClass = new JTextField(14); txtProgress = new JTextField(14); txtConduct = new JTextField(14); txtLeavingStudies = new JTextField(10); txtLeavingCollegeReason = new JTextField(14); txtFeeDue = new JTextField(14); btnRegister = new JButton("Register"); /*label general registration number*/ gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = 0; gbc.gridy = 0; gbc.weightx = 0.7; gbc.insets = new Insets( 10,20,10,20 ); gbLayout.setConstraints(lblGeneralRegistrationNumber,gbc); panel.add(lblGeneralRegistrationNumber); /*text general registration number*/ gbc.gridx = 1; gbc.gridy = 0; gbLayout.setConstraints(txtGeneralRegistrationNumber,gbc); panel.add(txtGeneralRegistrationNumber); /*label name*/ gbc.gridx = 4; gbc.gridy = 0; gbLayout.setConstraints(lblName,gbc); panel.add(lblName); /*text name*/ gbc.gridx = 5; gbc.gridy = 0; gbLayout.setConstraints(txtName,gbc); panel.add(txtName); /*label address*/ gbc.gridx = 0; gbc.gridy = 1; gbLayout.setConstraints(lblAddress,gbc); panel.add(lblAddress); /*text address*/ gbc.gridx = 1; gbc.gridy = 1; gbLayout.setConstraints(txtAddress,gbc); panel.add(txtAddress); /*label religion*/ gbc.gridx = 4; gbc.gridy = 1; gbLayout.setConstraints(lblReligion,gbc); panel.add(lblReligion); /*text religion*/ gbc.gridx = 5; gbc.gridy = 1; gbLayout.setConstraints(txtReligion,gbc); panel.add(txtReligion); /*label nationality*/ gbc.gridx = 0; gbc.gridy = 2; gbLayout.setConstraints(lblNationality,gbc); panel.add(lblNationality); /*text nationality*/ gbc.gridx = 1; gbc.gridy = 2; gbLayout.setConstraints(txtNationality,gbc); panel.add(txtNationality); /*label birth place*/ gbc.gridx = 4; gbc.gridy = 2; gbLayout.setConstraints(lblBirthPlace,gbc); panel.add(lblBirthPlace); /*text birth place*/ gbc.gridx = 5; gbc.gridy = 2; gbLayout.setConstraints(txtBirthPlace,gbc); panel.add(txtBirthPlace); /*label last school*/ gbc.gridx = 0; gbc.gridy = 3; gbLayout.setConstraints(lblLastSchool,gbc); panel.add(lblLastSchool); /*text last school*/ gbc.gridx = 1; gbc.gridy = 3; gbLayout.setConstraints(txtLastSchool,gbc); panel.add(txtLastSchool); /*label category*/ gbc.gridx = 4; gbc.gridy = 3; gbLayout.setConstraints(lblcategory,gbc); panel.add(lblcategory); /*text category*/ gbc.gridx = 5; gbc.gridy = 3; gbLayout.setConstraints(txtcategory,gbc); panel.add(txtcategory); /*label last school*/ gbc.gridx = 0; gbc.gridy = 4; gbLayout.setConstraints(lblAdmittedClass,gbc); panel.add(lblAdmittedClass); /*text last school*/ gbc.gridx = 1; gbc.gridy = 4; gbLayout.setConstraints(txtAdmittedClass,gbc); panel.add(txtAdmittedClass); /*label progress*/ gbc.gridx = 4; gbc.gridy = 4; gbLayout.setConstraints(lblProgress,gbc); panel.add(lblProgress); /*text progress*/ gbc.gridx = 5; gbc.gridy = 4; gbLayout.setConstraints(txtProgress,gbc); panel.add(txtProgress); /*label conduct*/ gbc.gridx = 0; gbc.gridy = 5; gbLayout.setConstraints(lblConduct,gbc); panel.add(lblConduct); /*text conduct*/ gbc.gridx = 1; gbc.gridy = 5; gbLayout.setConstraints(txtConduct,gbc); panel.add(txtConduct); /*label leaving studies*/ gbc.gridx = 4; gbc.gridy = 5; gbLayout.setConstraints(lblLeavingStudies,gbc); panel.add(lblLeavingStudies); /*text leaving studies*/ gbc.gridx = 5; gbc.gridy = 5; gbLayout.setConstraints(txtLeavingStudies,gbc); panel.add(txtLeavingStudies); /*label LeavingCollegeReason*/ gbc.gridx = 0; gbc.gridy = 6; gbLayout.setConstraints(lblLeavingCollegeReason,gbc); panel.add(lblLeavingCollegeReason); /*text LeavingCollegeReason*/ gbc.gridx = 1; gbc.gridy = 6; gbLayout.setConstraints(txtLeavingCollegeReason,gbc); panel.add(txtLeavingCollegeReason); /*label lblFeeDue*/ gbc.gridx = 4; gbc.gridy = 6; gbLayout.setConstraints(lblFeeDue,gbc); panel.add(lblFeeDue); /*text lblFeeDue*/ gbc.gridx = 5; gbc.gridy = 6; gbLayout.setConstraints(txtFeeDue,gbc); panel.add(txtFeeDue); [i] [color=orange] /* code to add combo box */ /*label date of birth*/ gbc.gridx = 0; gbc.gridy = 7; gbLayout.setConstraints(lblDob,gbc); panel.add(lblDob); gbc.gridx = 1; gbc.gridy = 7; gbLayout.setConstraints(dateCombo,gbc); panel.add(dateCombo); gbc.gridx = 1; gbc.gridy = 7; gbLayout.setConstraints(monthCombo,gbc); panel.add(monthCombo); gbc.gridx = 1; gbc.gridy = 7; gbLayout.setConstraints(yearCombo,gbc); panel.add(yearCombo); /* end combo boxes*/[/color][/i] /*label date of admission*/ panel.setLayout(gbLayout); gbc.gridx = 4; gbc.gridy = 7; gbLayout.setConstraints(lblAdmissionDate,gbc); panel.add(lblAdmissionDate); /*label date of leaving*/ gbc.gridx = 0; gbc.gridy = 8; gbLayout.setConstraints(lblLeavingDate,gbc); panel.add(lblLeavingDate); /*label date of receipt*/ gbc.gridx = 4; gbc.gridy = 8; gbLayout.setConstraints(lblReceiptDate,gbc); panel.add(lblReceiptDate); /*Button Register*/ Register rr = new Register(); gbc.gridx = 2; gbc.gridy = 9; gbc.ipady = 0; gbc.weighty = 0.8; gbLayout.setConstraints(btnRegister,gbc); btnRegister.addActionListener(rr); panel.add(btnRegister); panel.setBorder(new MatteBorder(5, 5, 30, 30, Color.lightGray)); } public class Register implements ActionListener { public void actionPerformed(ActionEvent e) { if(e.getSource()==btnRegister) { } } } public static void main(String args[]) { CustomerLayout cl = new CustomerLayout(); } }
VIEWS ON THIS POST

119

Posted on:

Wednesday 26th September 2012
View Replies!

JInternal frame little (or not) problem

Im creating a simple application where when I cklick on a button its load a JInternalFrame and show it up on the CENTER of my getContentPane() using BorderLayout. But the problem is that its only appear when I resize the main form.... Im using setVisible(true) on the constructor but its not working. See: .. .. public void actionPerformed(ActionEvent e) { if (e.getSource() == btnActors) { Helper.showError("Actors Clicked"); } if (e.getSource() == btnGameSettings) { JInternalFrame frame = new ProjectSettings(); contentPane.add(frame, BorderLayout.CENTER); //
VIEWS ON THIS POST

144

Posted on:

Wednesday 26th September 2012
View Replies!

problem in button ActionListener.

hello, i have a code to search from database, when i m printing the db field values, without any ActionListener, my code is working, i mean all the db field values are displaying in the JTable, but when i put the same code on buttonActionListener, my code is not working, but ActionListener is working... here is my code: import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Vector; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.border.EtchedBorder; import javax.swing.border.MatteBorder; import javax.swing.border.TitledBorder; public class Search extends JPanel{ JLabel lblSearchBy,lblRegistrationNumber,lblName; JTextField txtRegistrationNumber,txtName; Db db1 = new Db(); ResultSet resultSet; JComboBox searchBy; JButton searchButton; JTable table; String Name,RegistrationNumber; Vector headers=new Vector(); JScrollPane scrollPane; static Vector data=new Vector(); Search() throws ClassNotFoundException, SQLException { String[] searchByValues = {"Registration Number","Name"}; searchBy = new JComboBox(searchByValues); searchBy.setPreferredSize(new Dimension(100,18)); lblSearchBy = new JLabel("Select Search By"); lblRegistrationNumber = new JLabel("Enter Registration Number"); lblName = new JLabel("Enter Name"); txtRegistrationNumber = new JTextField(15); txtName = new JTextField(15); headers.add("First"); headers.add("Name"); headers.add("Age"); Name = txtName.getText(); RegistrationNumber = txtRegistrationNumber.getText(); searchButton = new JButton("Search"); this.setBorder(new MatteBorder(5, 5, 30, 30, Color.lightGray)); //resultSet = db1.connect(); /*while(resultSet.next()) { Vector d=new Vector(); d.add(resultSet.getString("FirstName")); d.add(resultSet.getString("LastName")); d.add(resultSet.getString("Age")); data.add(d); table = new JTable(data, headers); table.setPreferredScrollableViewportSize(new Dimension(500,50)); table.setFillsViewportHeight(true); }*/ Box horiz1 = Box.createHorizontalBox(); horiz1.add(lblSearchBy); horiz1.add(Box.createHorizontalStrut(100)); horiz1.add(searchBy); Box horiz2 = Box.createHorizontalBox(); horiz2.add(lblRegistrationNumber); horiz2.add(Box.createHorizontalStrut(47)); horiz2.add(txtRegistrationNumber); Object contents = searchBy.getSelectedItem(); Box horiz3 = Box.createHorizontalBox(); horiz3.add(lblName); horiz3.add(Box.createHorizontalStrut(130)); horiz3.add(txtName); Box horiz4 = Box.createHorizontalBox(); horiz4.add(searchButton); searchButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.out.println("Inside"); try { resultSet = db1.connect(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } try { while(resultSet.next()) { Vector d=new Vector(); d.add(resultSet.getString("FirstName")); d.add(resultSet.getString("LastName")); d.add(resultSet.getString("Age")); data.add(d); } } catch (SQLException e) { e.printStackTrace(); } } }); table = new JTable(data, headers); table.setPreferredScrollableViewportSize(new Dimension(500,50)); table.setFillsViewportHeight(true); scrollPane = new JScrollPane(table); Box horiz5 = Box.createHorizontalBox(); horiz5.add(scrollPane); Box vert = Box.createVerticalBox(); vert.add(Box.createVerticalStrut(100)); vert.add(horiz1); vert.add(Box.createVerticalStrut(30)); vert.add(horiz2); vert.add(Box.createVerticalStrut(30)); vert.add(horiz3); vert.add(Box.createVerticalStrut(30)); vert.add(horiz4); vert.add(Box.createVerticalStrut(60)); vert.add(horiz5); this.add(vert); } }
VIEWS ON THIS POST

214

Posted on:

Wednesday 26th September 2012
View Replies!

Is my problem because of 'StringBuilder'? Or do I need to some memory management (somehow)?

I can recall seeing this problem before, where outcome so I googled jtextarea read large files this might be worth a read http://www.dreamincode.net/forums/topic/224430-reading-in-large-text-files1gb-10gb-java-swing/ , probably worth posting your problem in the netbeans forum (search first - might get lucky), where you'll have many dedicated users/contributors who may have come across this issue before. http://forums.netbeans.org/
VIEWS ON THIS POST

135

Posted on:

Wednesday 26th September 2012
View Replies!

problem in creating advance installer

i have a standalone application with database connectivity. i have created jar file for that, also i have created executable file for that using (exe4j software). but the problem is:- one: i want to create some advance installer which should also come in add/remove(control panel), and which should be installable or setup like any software. second: database connectivity is not working in exe4j.
VIEWS ON THIS POST

110

Posted on:

Thursday 27th September 2012
View Replies!

problem in GridBagConstraints.fill

GridBagConstraints.fill is not working... here is my code.. import javax.swing.*; import java.awt.*; public class CustomerLayout extends JFrame { JPanel panel; JLabel labelCustName, labelCustNo, labelCustSex, labelCustAge; JTextField textCustName, textCustNumber, textCustAge; JComboBox comboCustSex; GridBagLayout gbLayout; GridBagConstraints gbc; public CustomerLayout() { gbLayout = new GridBagLayout(); gbc = new GridBagConstraints(); panel = new JPanel(); panel.setLayout(gbLayout); labelCustName = new JLabel("Customer Name"); labelCustNo = new JLabel("Customer Number"); labelCustSex = new JLabel("Customer Sex"); labelCustAge = new JLabel("Age"); textCustName = new JTextField(30); textCustNumber = new JTextField(15); textCustAge = new JTextField(2); String sex[] = {"Male","Female"}; comboCustSex = new JComboBox(sex); comboCustSex.setPreferredSize(new Dimension(100,20)); gbc.anchor = GridBagConstraints.NORTHWEST; gbc.gridx = 1; gbc.gridy = 5; gbc.insets = new Insets(5,5,5,5); gbc.fill = GridBagConstraints.HORIZONTAL; gbLayout.setConstraints(labelCustName,gbc); panel.add(labelCustName); gbc.anchor = GridBagConstraints.NORTHWEST; gbc.gridx = 4; gbc.gridy = 5; gbLayout.setConstraints(textCustName,gbc); panel.add(textCustName); gbc.gridx = 1; gbc.gridy = 6; gbLayout.setConstraints(labelCustNo,gbc); panel.add(labelCustNo); gbc.gridx = 4; gbc.gridy = 6; gbLayout.setConstraints(textCustNumber,gbc); panel.add(textCustNumber); gbc.gridx = 1; gbc.gridy = 7; gbLayout.setConstraints(labelCustSex,gbc); panel.add(labelCustSex); gbc.gridx = 4; gbc.gridy = 7; gbLayout.setConstraints(comboCustSex,gbc); panel.add(comboCustSex); this.add(panel, BorderLayout.NORTH); this.setSize(500,200); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } public static void main(String args[]) { CustomerLayout cl = new CustomerLayout(); } }
VIEWS ON THIS POST

162

Posted on:

Thursday 27th September 2012
View Replies!

problem in GridBagLayout

hello i m designing a registration form in swing, initial i added two textfields and labels to my frame, but the only one textbox is visible to me and when i maximize the screen, label is also visible to me but inside the text box, but second label and text boxes are not visible to me.. i m using GridBagLayout. here is my code: import javax.swing.*; import java.awt.*; import javax.swing.event.*; public class Form extends JFrame{ private Container c; private GridBagLayout gbLayout; private GridBagConstraints gbConstratints; public static void main(String args[]) { new Form(); } public Form() { c = getContentPane(); gbLayout = new GridBagLayout(); c.setLayout(gbLayout); gbConstratints = new GridBagConstraints(); JLabel name = new JLabel("Name"); JLabel age = new JLabel("Age"); JTextField ta= new JTextField(30); JTextField tx= new JTextField(30); gbConstratints.fill = GridBagConstraints.HORIZONTAL; addComponent(name,0,0,0,0); gbConstratints.fill = GridBagConstraints.HORIZONTAL; addComponent(ta,0,1,2,0); gbConstratints.fill = GridBagConstraints.HORIZONTAL; addComponent(age,1,0,0,1); gbConstratints.fill = GridBagConstraints.HORIZONTAL; addComponent(tx,1,1,1,1); this.setSize(500,550); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private void addComponent(Component cn, int row, int column, int width, int height) { gbConstratints.gridx = column; gbConstratints.gridy = row; gbConstratints.gridwidth = width; gbConstratints.gridheight = height; gbLayout.setConstraints(cn, gbConstratints); c.add(cn); } }
VIEWS ON THIS POST

166

Posted on:

Thursday 27th September 2012
View Replies!

problem with jradiobuttonMenuItem

i have a 2 JRAdioButtonMenuItem in a group , my problem is when i select any one of them , then after that, when i use menuitems the up & down arrow keys just get stuck i mean they don't work and i have to move it ups and down using mouse can any one knows why i m facing such wired situation
VIEWS ON THIS POST

150

Posted on:

Friday 28th September 2012
View Replies!

problem regarding loop in buttons

import java.awt.*; class Calculator { int i; Frame f; Button b[]=new Button[50]; TextField tf; Calculator() { int i=0; int x=0; int y=0; f=new Frame(); tf=new TextField(); tf.setBounds(30,40,300,30); f.add(tf); for(i=0;i
VIEWS ON THIS POST

164

Posted on:

Friday 28th September 2012
View Replies!

SWT table problem

Hi , DOes anyone know how to save the data from an editable table cell into an array in java. Any help will be appreciate it. For instance i have table with 3 columns and 4 rows. the 3rd column is editable so the users can enter data. Once they fill the 3rd column I want to save that data into an array or something so i can use it for later. Is there any suggestions
VIEWS ON THIS POST

149

Posted on:

Saturday 29th September 2012
View Replies!

Program.launch of Mac OSX TextEdit can cause problems

My SWT application has been used in both Windows XP/Vista/7 and Mac OSX for several years. Recently, in certain org.eclipse.jface.action.Action classes I've added the option to open *.txt files (these are newly created operational reports). The files are opened by calling org.eclipse.swt.program.Program.launch(fileName), where fileName is the full path name for a particular *.txt file. In Windows, there are no issues with this scenario. In Mac OSX, if the user first launches the text-related program (e.g., TextEdit) before launching my SWT application, there are no issues with this scenario. In Mac OSX, if the user first exits the text-related program (e.g., TextEdit) launched by my SWT application before attempting to exit my SWT application (via menu's "Quit", etc.), there are no issues with this scenario. In Mac OSX, if the users does not exit the text-related program (e.g., TextEdit) launched by my SWT application before attempting to exit my SWT application, my SWT application's window closes... but the icon is left behind in the Dock (a.k.a., system taskbar) and my SWT application has not actually exited. I have to manually terminate my SWT application via Force Quit. Any suggestions about this problem would be welcome.
VIEWS ON THIS POST

239

Posted on:

Sunday 30th September 2012
View Replies!

problem in setting background image of jpanel

i m not able to set a background image of my JPanel, can anyone tell me how do i set JPanel Background image\t here is my code, in which i m setting the background color of my JPanel but i want to set an image instead: import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.Random; class Test { public static void main(String args[]) { JFrame frame = new JFrame(); Cpoint point = new Cpoint(); Cdynamic d = new Cdynamic(point); Cair ca= new Cair(); d.panel.setBackground(Color.ORANGE); point.setBackground(new Color(0,0,255)); JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, d.panel, point); Container c = frame.getContentPane(); c.add(sp, BorderLayout.CENTER); ca.setPreferredSize(new Dimension(200,0)); c.add(ca, BorderLayout.EAST); frame.setVisible(true); frame.setSize(1280,750); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } class Dynamic extends JPanel { JPanel panel; JButton button; JLabel label; Cpoint cp; Dynamic(Cpoint c) { cp = c; System.out.println("Inside Dynamic class"); panel = new JPanel(); panel.setBackground(Color.yellow); button = new JButton("Fish Die"); label = new JLabel("Label to test"); panel.add(button); panel.add(label); button.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae){ cp.fishAlive = false; if(cp.timer != null && cp.timer.isRunning()) { cp.timer.stop(); cp.repaint(); } } }); } } class Cpoint extends JPanel implements ActionListener{ Cfish1 ball,ball2,ball3,ball4,ball5,ball6; Cbubble1 bull,bull2,bull3,bull4,bull5,bull6,bull7,bull8,bull9,bull10; int newx, newy, midx,midy,getradius, newwidth, newheight; Timer timer; int count; boolean fishAlive = true; int counter = 0; Cpoint() { timer = new Timer(26, this); timer.start(); ball = new Cfish1(500,100, new ImageIcon("g:\\fish\\fish1.jpg").getImage()); bull = new Cbubble1(20,400); } public void paintComponent(Graphics g) { super.paintComponent(g); if(fishAlive) { ball.DisplayFish(g); bull.DisplayBubble(g); } } public void actionPerformed(ActionEvent e) { ball.movementFish(this); bull.movement_bubble(this); try { repaint(); } catch (Exception ex) { ex.printStackTrace(); } System.out.println("timer "+(counter++)); } } class Cfish1 { int x = 2; int y = 5; int dx = 2; int dy = 1; int radius = 9; Image fishImg; public Cfish1() {} public Cfish1(int x, int y,Image img) { fishImg = img; this.x = x; this.y = y; radius = fishImg.getWidth(null)/2; } public int getRadius() { return radius; } public void movementFish(Cpoint sp) { if(x+dx>sp.getWidth()-radius-4) { x = sp.getWidth()-radius-2; dx = -dx; } else if(x+dxsp.getHeight()-radius-4) { y = sp.getHeight()-radius-4; dy = -dy; } else if(y+dysp.getHeight()-bulradius-4) { buly = sp.getHeight()-bulradius-4; bulradius++; if(bulradius==6) bulradius=1; } else if(buly+buldy
VIEWS ON THIS POST

260

Posted on:

Sunday 30th September 2012
View Replies!

problem in border layout.

i add two classes with border layout to my frame, one is in center and one is in south but in the border layout "If nothing has been added to a region, the neighboring regions expand to fill that space." here also this is happening, but i want the space in the west and east also, i mean my class which is in center should not expand the neighbor space(ie. west and east), how to do this\t
VIEWS ON THIS POST

133

Posted on:

Sunday 30th September 2012
View Replies!

problem in creating more than one objects

i have 5 classes, here is:- Cbubble.java import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Image; import javax.swing.*; public class Cbubble { private int bulx=0; private int buly=0; private int buldx=0; private int buldy=-2; private int bulradius = 2; String bName; public Cbubble() { } public Cbubble(int i, int j) { bulx=i; buly=j; } public void movement_bubble(Cpoint sp) { if(buly+buldy>sp.getHeight()-bulradius-4) { buly = sp.getHeight()-bulradius-4; bulradius++; if(bulradius==6) bulradius=1; } else if(buly+buldy
VIEWS ON THIS POST

196

Posted on:

Monday 1st October 2012
View Replies!

changing headers on JTable caused other problems

Hi Guys, I'm working with a JTable which sets up certain columns with cell renderers and editors. My application allows the user to change the interface to a different language, so JMenuItems, buttons, etc. change their text and I've set it up so that the header on the JTable changes as well. Two lines of code make that happen: private void changeTableHeaders() { ((JLTableModel)table.getModel()).setHeaders(this.getHeaders()); ((JLTableModel)table.getModel()).fireTableStructureChanged(); }
VIEWS ON THIS POST

213

Posted on:

Monday 1st October 2012
View Replies!

problem in JSplitPane

not able to add into JSplitPane.. import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JSplitPane; import javax.swing.JTextArea; public class Ctank { static String sometext = "This is a simple text to test....."; public static void main(String args[]) { JFrame frame = new JFrame(); frame.setVisible(true); frame.setSize(800,600); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea jt1 = new JTextArea(sometext); Cpoint point = new Cpoint(); JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, point, jt1); frame.getContentPane().add(sp, BorderLayout.CENTER); } } i m not able to add components to JSplitPane, here i m trying to add simple a JTextField and one class CPoint (which exteding JPanel), but on the frame, when i m executing the code nothing is visible to me, what wrong i am doing\t
VIEWS ON THIS POST

195

Posted on:

Monday 1st October 2012
View Replies!

Really, really weird GUI problem

Hi Everybody!! I have a very weird problem with a Java GUI that I've built at work. It is so weird I don't even know where to start to look for help!! I hope this is the place; if not, I apologize. We have a standalone system at an offsite location consisting of a Windows PC, running XP, and a SuSE Linux machine. I built a Java GUI that runs some bash scripts on the Linux machine. The GUI is started from the Windows machine because the user is not a Linux person. The GUI was built to replace scripts that presented the user with command line prompts for providing inputs to the main processing scripts. The user clicks an icon on the windows desktop which runs a DOS batch (*.bat) file. The batch file uses plink, with a stored PuTTY session, to connect to the Linux machine and to execute a "java -jar XXX.jar" command to start the GUI. The GUI displays on the Windows PC due to Cygwin/X X Server running on the windows PC. Okay. Now for the weirdness. If I leave the GUI in the location where it initially pops up, everything is fine. If I move the GUI, then the pulldown menus (dropdown combo boxes and menubar pulldowns) no longer work properly. And ONLY the pulldown menus. Everything else works fine (pushbuttons, text fields, ...). If I move the GUI back to its original location, everything works fine. If I click, hold and drag the mouse cursor over to where the GUI initially popped up (leaving the GUI where I moved it) the pulldown menus work properly. At first I thought I had a problem with the way I initialized the pull down menus but I'm not so sure anymore. I'm wondering if there is something weird going on with the windows putty linux or the Xwin setups. Contributing to not being able to solve this is that I cannot replicate this behavior at work. Unfortunately we don't have an exact replica of the offsite system; I'm testing/building this GUI on a XP to Debian Linux machine. As anybody seen anything like this Any suggestion as to what might be going on here
VIEWS ON THIS POST

174

Posted on:

Monday 1st October 2012
View Replies!

Java Image Capture, Buffered Image, Paste in MSWord 2007 problem

I have asked a related question before...but there was no reply. I dont know how to revoke it (may get an answer this time).. so i thought i would ask again.. I am changing the problem statement a bit. Consider the following code for capturing a part of the screen import java.awt.AWTException; import java.awt.Rectangle; import java.awt.Robot; import java.awt.Toolkit; import java.awt.image.BufferedImage; public class Capture { public static void main(String[] args) throws AWTException { Rectangle rectangle = new Rectangle(200, 200, 200, 200); BufferedImage img = new Robot().createScreenCapture(rectangle); ImageToClipboard imageToClipboard = new ImageToClipboard(img); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(imageToClipboard, null); } }
VIEWS ON THIS POST

149

Posted on:

Monday 1st October 2012
View Replies!

scrollpane problem

i m making an editor, which has one panel , which inturn has labels which contains the line number and the editor is with frame the problem is when i reachs end of the line surely editor goes up (similar when you type at the end and scrollpane allows you to view the text at the bottom of your editor) my problem is line numbers label doesnt go in upward (though it is in scrollpane) for eg line number max goes to 35 then the screen finishes after that when i press enter editor scrolls down but this number panel doesnt scrolls down i guess this will give you a better idea...what is going wrong public class LineNumberOnEditor { /** * @param args the command line arguments */ private static JEditorPane editor; private JPanel panel; private JFrame frame; private int counter; private PrintWriter tempOut,htmlOut; private BufferedReader reader; private File tempFileLocation, htmlFileLocation; private JLabel numberLabel; private int lineNoInt = 0; private Integer lineNO = lineNoInt; private JPanel lineNumberPanel ; private JScrollPane scrollpane , lineNoScrollpane; private Font font ; public void startEditor() { frame = new JFrame("Editor"); panel = new JPanel(); editor = new JEditorPane(); editor.setPreferredSize(new Dimension(1350,850)); scrollpane = new JScrollPane(editor); numberLabel = new JLabel(lineNO.toString(),JLabel.RIGHT); settingCommonFont(); settingLineNo(); settingKeyAdapter(); numberLabel.setFont(font); editor.setFont(font); editor.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); frame.add(scrollpane,BorderLayout.CENTER); frame.add(lineNoScrollpane,BorderLayout.WEST); frame.pack(); frame.setExtendedState(JFrame.MAXIMIZED_BOTH); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true); } public static void main(String[] args) { // TODO code application logic here new LineNumberOnEditor().startEditor(); } private void settingKeyAdapter() { class KeyListener extends KeyAdapter { @Override public void keyPressed(KeyEvent e) { if(e.getKeyCode() == KeyEvent.VK_ENTER) { incrementingLNumber(); } } private void incrementingLNumber() { lineNoInt++; lineNO = lineNoInt; JLabel numberLabel = new JLabel(lineNO.toString()); lineNumberPanel.add(numberLabel); lineNumberPanel.updateUI(); numberLabel.setFont(font); System.out.println(lineNoInt); } } editor.addKeyListener(new KeyListener()); } private void settingLineNo() { lineNumberPanel = new JPanel(); lineNumberPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 0)); lineNumberPanel.setPreferredSize(new Dimension(60,5)); BoxLayout box = new BoxLayout(lineNumberPanel, BoxLayout.Y_AXIS); lineNumberPanel.setLayout(box); lineNumberPanel.add(numberLabel); lineNoScrollpane = new JScrollPane(lineNumberPanel,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); } private void settingCommonFont() { font = new Font("Times New Roman",Font.BOLD,18); } }
VIEWS ON THIS POST

189

Posted on:

Wednesday 3rd October 2012
View Replies!

problem in getPosition and setPosition......

Cpoint.java import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Cpoint extends JPanel implements Runnable{ int x =400; int y = 25; int dx = 4; int dy = 1; int radius = 20; Cpoint() { Thread thread = new Thread(this); thread.start(); } /*public void setPosition(int x) { this.x = x; }*/ public int getPosition() { return x; } public void run() { // TODO Auto-generated method stub while(true) { if(x+dx>this.getWidth()-radius) { x = this.getWidth()-radius-1; dx = -dx; } else if(x + dx < 0+radius) { x = 0+radius; dx = -dx; } else { x+=dx; } if(y+dy>this.getHeight()-radius) { y = this.getHeight()-radius-1; dy = -dy; } else if(y + dy < 0+radius) { y = 0+radius; dy = -dy; } else { y+=dy; } x+=dx; repaint(); try { Thread.sleep(17); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.BLUE); g.fillOval(x-radius, y-radius, radius*2,radius*2); System.out.println(this.getPosition()); } }
VIEWS ON THIS POST

132

Posted on:

Wednesday 3rd October 2012
View Replies!