Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Appli compteur de points Basket
package com.example.android.courtcounter;
import android.graphics.drawable.Drawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
int scoreTeamA;
int scoreTeamB;
/**
* Adds 3 points to scoreTeamA
*/
public void plus3TeamA (View view){
scoreTeamA = scoreTeamA +3;
displayForTeamA(scoreTeamA);
}
/**
* Adds 2 points to scoreTeamA
*/
public void plus2TeamA (View view){
scoreTeamA = scoreTeamA +2;
displayForTeamA(scoreTeamA);
}
/**
* Adds 1 point to scoreTeamA
*/
public void plus1TeamA (View view){
scoreTeamA = scoreTeamA +1;
displayForTeamA(scoreTeamA);
}
/**
* Adds 3 points to scoreTeamB
*/
public void plus3TeamB (View view){
scoreTeamB = scoreTeamB +3;
displayForTeamB(scoreTeamB);
}
/**
* Adds 2 points to scoreTeamB
*/
public void plus2TeamB (View view){
scoreTeamB = scoreTeamB +2;
displayForTeamB(scoreTeamB);
}
/**
* Adds 1 point to scoreTeamA
*/
public void plus1TeamB (View view){
scoreTeamB = scoreTeamB +1;
displayForTeamB(scoreTeamB);
}
/**
* resets both scores to 0
*/
public void reset (View view){
scoreTeamA=0;
scoreTeamB=0;
displayForTeamA(scoreTeamA);
displayForTeamB(scoreTeamB);
}
/**
* Displays the given score for Team A.
*/
public void displayForTeamA(int scoreTeamA) {
TextView scoreView = (TextView) findViewById(R.id.score_team_A);
scoreView.setText(String.valueOf(scoreTeamA));
}
/**
* Displays the given score for Team B.
*/
public void displayForTeamB(int scoreTeamB) {
TextView scoreView = (TextView) findViewById(R.id.score_team_B);
scoreView.setText(String.valueOf(scoreTeamB));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/dunkjordan"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1"
android:layout_marginTop="12dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Team A"
android:textSize="24sp"
android:textColor="#ffffff"
android:fontFamily="sans-serif"/>
<TextView
android:id="@+id/score_team_A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="54sp"
android:padding="16dp"
android:textColor="#ffffff"/>
<Button
android:id="@+id/plus_3_Team_A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+3 points"
android:textSize="20sp"
android:padding="8dp"
android:onClick="plus3TeamA"/>
<Button
android:id="@+id/plus_2_Team_A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+2 points"
android:textSize="20sp"
android:padding="8dp"
android:onClick="plus2TeamA"/>
<Button
android:id="@+id/plus_1_Team_A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Free throw"
android:textSize="20sp"
android:padding="8dp"
android:onClick="plus1TeamA"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Team B"
android:textSize="24sp"
android:textColor="#ffffff"
android:fontFamily="sans-serif"/>
<TextView
android:id="@+id/score_team_B"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="54sp"
android:padding="16dp"
android:textColor="#ffffff"/>
<Button
android:id="@+id/plus_3_Team_B"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+3 points"
android:textSize="20sp"
android:padding="8dp"
android:onClick="plus3TeamB"/>
<Button
android:id="@+id/plus_2_Team_B"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+2 points"
android:textSize="20sp"
android:padding="8dp"
android:onClick="plus2TeamB"/>
<Button
android:id="@+id/plus_1_Team_B"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Free throw"
android:textSize="20sp"
android:padding="8dp"
android:onClick="plus1TeamB"/>
</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:layout_weight="0"
android:text="Reset scores"
android:textSize="20sp"
android:onClick="reset"/>
</LinearLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment