+ 1
How to create button in apk android?
Help How to make a button if pressed to generate number 1 and if not pressed to produce 0?
6 Answers
+ 1
button.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick (View v)
{
System.out.println("1")
}});
+ 1
I Edited your program: This example will not run in sololearn (I don`t know why), but with a dedicated environment like Netbeans it will
public class Program
{
public static void main(String[] args) {
JFrame trFrame = new JFrame("frame"); //
trFrame.setBounds(500,200,280,150);
trFrame.setVisible(true);
trFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = new Container();
trFrame.add(c);
Button button = new Button("button");
button.setBounds(0,0,100,150);
c.add(button);
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println("1")
}
});
}
}
0
sorry.this program use java,php or web in sollo learn?
0
It is for android as you requested, but can be easily adapted for
java:
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println("1")
}
});
0
example :
don't work
https://code.sololearn.com/cXM1g57kNFI5/?ref=app
0
thank you very much friend.