🔒 Closed Patulong po sa codes

Status
Not open for further replies.

euls020

Enthusiast
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class jb extends Applet implements ItemListener,ActionListener{
public jb() {
setFont(new Font("Arial", Font.BOLD, 14));
setBackground(Color.YELLOW);
setForeground(Color.BLUE);
}
Label l;
TextField r,s,j,p;
Choice c;
Button pr;
public void init()
{
l=new Label("Costumers Order");
add(l);
l=new Label("Regular---30");
add(l);
r=new TextField (5);
add(r);
l=new Label("Special---40");
add(l);
s=new TextField (5);
add(s);
l=new Label("Jumbo---50");
add(l);
j=new TextField (5);
add(j);
c =new Choice();
c.addItem("Table 1");
c.addItem("Table 2");
c.addItem("Table 3");
c.addItem("Table 4");
c.addItem("Table 5");
c.addItemListener(this);
add(c);
pr=new Button ("Price");
add(pr);
pr.addActionListener(this);
p=new TextField (10);
add(p);
}
public void actionPerformed(ActionEvent objEvent) {
if(objEvent.getSource()==pr){
int r1=0,r2=0,s1=0,s2=0,j1=0,j2=0,p1;
r1=Integer.parseInt(r.getText());
s1=Integer.parseInt(s.getText());
j1=Integer.parseInt(j.getText());
r2=r1*30;
s2=s1*40;
j2=j1*50;
p1=r2+s2+j2;
p.setText(String.valueOf(p1));

}
}

public void itemStateChanged(ItemEvent e) {
}
}

------
Nagana naman po. ang di ko lang po matanggal ay yung error na kapag hindi naglagay ng order sa lahat ay nag eerror pero kapag nilagyan po ng mga 0 ayos naman po. pano po ba maseset na equals to zero na yung mga yun kahit di na lagyan po. thanks po.
 
tama yung code mo Integer.parseInt - meaning it reads the text and kung meron Integer na makita, gagawin niyang int.

heto isang solution sa error na nkikita mo. hint lang:
- paano kung isEmpty yung textbox? anong value ang ibibigay?
- subukan mong lagyan ng conditions

Suggestion: Puwede bang ugaliin mong magbigay ng mga MEANINGFUL name sa mga variables mo?
instead na r1, gawin mong regularPriceBox, instead na j1, gawin mong jumboPriceBox, instead na p1 ay gawin mong priceBox, etc. etc.....at saka yung pangalan ng class mo na jb.... either you rename it to Jb or a more meaningful name.
***variable naming: notCapitalizedFirstLetter
***class naming: FirstLetterCapitalized
(Just a friendly reminder to follow Java naming convention para sa future job mo :) )
 
solution hint #2:
- paano kung BAGO ka mag perform ng action ay "lilinisin mo muna" yung mga textboxes?
ano kaya mangyayari?

Pag nagawa mo na itong SOLUTION HINTS #1 and #2.
Solve na yung problema ng code mo.

PERO.....ang next question is, paano kung text ang inilagay sa mga textboxes (instead na numero). Paano mo i-ha-handle yung error??
- hint: "parse-able" ba yung text value, true or false?
 
solution hint #2:
- paano kung BAGO ka mag perform ng action ay "lilinisin mo muna" yung mga textboxes?
ano kaya mangyayari?

Pag nagawa mo na itong SOLUTION HINTS #1 and #2.
Solve na yung problema ng code mo.

PERO.....ang next question is, paano kung text ang inilagay sa mga textboxes (instead na numero). Paano mo i-ha-handle yung error??
- hint: "parse-able" ba yung text value, true or false?
salamat po. pasensya na po sa grade12 pa lang po eh. next time po. ty.

marunong po ba kayo sir sa layouting? di kasi tinuturo pa samin. pero kailangan ko pong gamitan yang code nayan improve ko pa daw po yung interface niya. pasensya na po kung may dagdag pa po akong katanungan. ty
 
ayos kung grade 12 ka pa lang.
Madali ka pang turuan ng tama (in terms of Java naming conventions).
So keep in mind, variable name is lowercase first word, class name is UPPERCASE first word....and both use camel casing on succeeding words. (ThisIsAClassName, thisIsAVariableName).

sa layouting, you can read here.
You do not have permission to view the full content of this post. Log in or register now.
maraming options. may mga third party but just stick here muna.

Be careful when you use the word "interface". In Java, it means a "class" with just methods and fields signatures. Pero kung ang ibig mong sabihin ng interface ay yung Graphical User Interface, just use GUI or call it "the look".

Keep learning Java, maganda sahod ng Java programmer ($$$$$).
 
Ay yong problema no nga pala yung error pag walang laman and inputs no ganun?? Pag walng laman and text fields automatic ang value nia ay NULL.. Kaya sya nag error kac Hindi string ang null at Hindi rin sya integer.. Gumawa ka nalang ng conditional statement na pay walng laman ang input e seset into zero ang value..
 
Ay yong problema no nga pala yung error pag walang laman and inputs no ganun?? Pag walng laman and text fields automatic ang value nia ay NULL.. Kaya sya nag error kac Hindi string ang null at Hindi rin sya integer.. Gumawa ka nalang ng conditional statement na pay walng laman ang input e seset into zero ang value..
boss may bago po akong problema. di po ma unlock yung textfield. :(
problem.webp
 
ayos kung grade 12 ka pa lang.
Madali ka pang turuan ng tama (in terms of Java naming conventions).
So keep in mind, variable name is lowercase first word, class name is UPPERCASE first word....and both use camel casing on succeeding words. (ThisIsAClassName, thisIsAVariableName).

sa layouting, you can read here.
You do not have permission to view the full content of this post. Log in or register now.
maraming options. may mga third party but just stick here muna.

Be careful when you use the word "interface". In Java, it means a "class" with just methods and fields signatures. Pero kung ang ibig mong sabihin ng interface ay yung Graphical User Interface, just use GUI or call it "the look".

Keep learning Java, maganda sahod ng Java programmer ($$$$$).
pwede po ba patulong uli? bat po ayaw ma unlock yung textfield. JCheckbox po gamit ko at nasa actionPerformed po siya
problem.png
 
Ay yong problema no nga pala yung error pag walang laman and inputs no ganun?? Pag walng laman and text fields automatic ang value nia ay NULL.. Kaya sya nag error kac Hindi string ang null at Hindi rin sya integer.. Gumawa ka nalang ng conditional statement na pay walng laman ang input e seset into zero ang value..
alam ko na pala po. thanks
 
ayos kung grade 12 ka pa lang.
Madali ka pang turuan ng tama (in terms of Java naming conventions).
So keep in mind, variable name is lowercase first word, class name is UPPERCASE first word....and both use camel casing on succeeding words. (ThisIsAClassName, thisIsAVariableName).

sa layouting, you can read here.
You do not have permission to view the full content of this post. Log in or register now.
maraming options. may mga third party but just stick here muna.

Be careful when you use the word "interface". In Java, it means a "class" with just methods and fields signatures. Pero kung ang ibig mong sabihin ng interface ay yung Graphical User Interface, just use GUI or call it "the look".

Keep learning Java, maganda sahod ng Java programmer ($$$$$).
alam ko na pala po thanks
 
heto, pangtapal na solution.
(It's not the best solution. Pero puwede para lang tumakbo ng walang error ang application mo. Para makatulog ka na.. :)
 

Attachments

  • solution.webp
    solution.webp
    92.3 KB · Views: 29
22.webp
heto, pangtapal na solution.
(It's not the best solution. Pero puwede para lang tumakbo ng walang error ang application mo. Para makatulog ka na.. :)
ito na po talaga ang last pano po ba malalagyan ng background ang isang panel sa applet? kaya po ba? puro po kasi sa netbeans nakikita ko at JPanel. eclipse lang po gamit ko eh.
 
heto, mga hints mo (as always)..:)

***this will take care of the image and displaying (basahin mo sa Java Doc)
***kung kaya mo, gawa ka ng separate class para dito
1) ano kaya mangyayari i-e-extends mo ang JPanel class
2) and then use Image class to hold your "background.jpg" image
3) ano kaya kung gagamitin ko ang paintComponent(Graphics g)

That's all you need, bro.
(Of course, there are few ways to achieve it...BUT... these are the Java CLASSES na kailangan regardless kung ano approach mo)
 
heto, mga hints mo (as always)..:)

***this will take care of the image and displaying (basahin mo sa Java Doc)
***kung kaya mo, gawa ka ng separate class para dito
1) ano kaya mangyayari i-e-extends mo ang JPanel class
2) and then use Image class to hold your "background.jpg" image
3) ano kaya kung gagamitin ko ang paintComponent(Graphics g)

That's all you need, bro.
(Of course, there are few ways to achieve it...BUT... these are the Java CLASSES na kailangan regardless kung ano approach mo)
hahaha. salamat po. kanina ko pa nga po napapansin yang paintComponent na yan sa mga nasesearch ko
 
hahaha. salamat po. kanina ko pa nga po napapansin yang paintComponent na yan sa mga nasesearch ko
di ko po talaga magets kung pano. hahaha. maghapon ng nakatutuk sa com. ang slow ko po. hahaha. di ko nalang po lalagyan. :):). ang nalaman ko lang pong pag lalagay ng image ay dun sa hindi ginamitan ng panel po eh. hahaha. Salamat po.
 
hahaha. salamat po. kanina ko pa nga po napapansin yang paintComponent na yan sa mga nasesearch ko
ano po ba mali ko o kulang ko dito sa paintComoponent?
----
class BackGroundPanel extends JPanel {
Image backGround;

public void paintComponent(Graphics g)
{
backGround = getImage(getCodeBase(), "file:///C:/Users/Windows7/workspace/John%20Byron/6218548.jpg");
super.paintComponent(g);

g.drawImage(backGround, 0, 0,
(int)getBounds().getWidth(), (int)getBounds().getHeight(), this);


}

public void itemStateChanged(ItemEvent arg0) {

}
}
}
errorrr.png
 
OK, I think you've tried your best enough. :D
Kung ako sa iyo, ganito ang approach ko (kung sakaling 5 minutes lang ang ibibigay sa akin para gawin)
- pinag hiwalay ko yung dalawang classes para makita mo ng malinaw
- MainApp.java is the main app.
- JPanelBackground.java ay taga gawa lang ng panel na may parameter na image

check snapshots below.

***Take notes
1) use RELATIVE file directory pag nagse-save ka ng images. Relative path or relative package. Huwag mong isasama ang path ng hard drive mo.
2) sa MainApp, ginawa ko "setOpaque(false)" yung nasa nasa ibabaw na panel ("panel2). This is the key para makita yung nasa ilalim na panel na may background.
3) tignan mo yung layout ng code.... naka indent para madaling masundan
4) yung pag construct ko ng component, you can use your style para madaling maglagay ng events listener later.
Goodluck, again! :)
 

Attachments

  • Jpanelbackgroundclass.webp
    Jpanelbackgroundclass.webp
    34.1 KB · Views: 24
  • mainapp.webp
    mainapp.webp
    78.8 KB · Views: 23
  • output.webp
    output.webp
    11.3 KB · Views: 24
Status
Not open for further replies.

Similar threads

About this Thread

  • 22
    Replies
  • 1K
    Views
  • 3
    Participants
Last reply from:
euls020

Trending Topics

Online now

Members online
1,150
Guests online
1,018
Total visitors
2,168

Forum statistics

Threads
2,274,693
Posts
28,957,671
Members
1,233,403
Latest member
uradox
Back
Top